@fgv/ts-res 5.1.0-2 → 5.1.0-4
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/packlets/config/common.js +78 -0
- package/dist/packlets/config/configInitFactory.js +258 -0
- package/dist/packlets/config/convert.js +56 -0
- package/dist/packlets/config/index.browser.js +34 -0
- package/dist/packlets/config/index.js +28 -0
- package/dist/packlets/config/json.js +23 -0
- package/dist/packlets/config/predefined/default.js +138 -0
- package/dist/packlets/config/predefined/extended.js +190 -0
- package/dist/packlets/config/predefined/index.js +25 -0
- package/dist/packlets/config/systemConfiguration.js +147 -0
- package/dist/packlets/qualifier-types/config/convert.js +124 -0
- package/dist/packlets/qualifier-types/config/index.js +25 -0
- package/dist/packlets/qualifier-types/config/json.js +32 -0
- package/dist/packlets/resource-types/config/convert.js +35 -0
- package/dist/packlets/resource-types/config/index.js +25 -0
- package/dist/packlets/resource-types/config/json.js +23 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/packlets/config/common.d.ts +35 -0
- package/lib/packlets/config/common.js +97 -0
- package/lib/packlets/config/configInitFactory.d.ts +217 -0
- package/lib/packlets/config/configInitFactory.js +303 -0
- package/lib/packlets/config/convert.d.ts +23 -0
- package/lib/packlets/config/convert.js +93 -0
- package/lib/packlets/config/index.browser.d.ts +7 -0
- package/lib/packlets/config/index.browser.js +74 -0
- package/lib/packlets/config/index.d.ts +7 -0
- package/lib/packlets/config/index.js +68 -0
- package/lib/packlets/config/json.d.ts +20 -0
- package/lib/packlets/config/json.js +24 -0
- package/lib/packlets/config/predefined/default.d.ts +57 -0
- package/lib/packlets/config/predefined/default.js +141 -0
- package/lib/packlets/config/predefined/extended.d.ts +25 -0
- package/lib/packlets/config/predefined/extended.js +193 -0
- package/lib/packlets/config/predefined/index.d.ts +4 -0
- package/lib/packlets/config/predefined/index.js +62 -0
- package/lib/packlets/config/systemConfiguration.d.ts +94 -0
- package/lib/packlets/config/systemConfiguration.js +152 -0
- package/lib/packlets/qualifier-types/config/convert.d.ts +65 -0
- package/lib/packlets/qualifier-types/config/convert.js +161 -0
- package/lib/packlets/qualifier-types/config/index.d.ts +4 -0
- package/lib/packlets/qualifier-types/config/index.js +64 -0
- package/lib/packlets/qualifier-types/config/json.d.ts +91 -0
- package/lib/packlets/qualifier-types/config/json.js +35 -0
- package/lib/packlets/resource-types/config/convert.d.ts +8 -0
- package/lib/packlets/resource-types/config/convert.js +38 -0
- package/lib/packlets/resource-types/config/index.d.ts +4 -0
- package/lib/packlets/resource-types/config/index.js +64 -0
- package/lib/packlets/resource-types/config/json.d.ts +11 -0
- package/lib/packlets/resource-types/config/json.js +24 -0
- package/package.json +28 -26
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.ExtendedSystemConfiguration = exports.ExtendedResourceTypes = exports.ExtendedQualifiers = exports.ExtendedQualifierTypes = void 0;
|
|
25
|
+
/**
|
|
26
|
+
* Example extended qualifier types.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
exports.ExtendedQualifierTypes = [
|
|
30
|
+
{
|
|
31
|
+
name: 'language',
|
|
32
|
+
systemType: 'language',
|
|
33
|
+
configuration: {
|
|
34
|
+
allowContextList: true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'territory',
|
|
39
|
+
systemType: 'territory',
|
|
40
|
+
configuration: {
|
|
41
|
+
allowContextList: false,
|
|
42
|
+
acceptLowercase: false
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'role',
|
|
47
|
+
systemType: 'literal',
|
|
48
|
+
configuration: {
|
|
49
|
+
enumeratedValues: ['admin', 'agent', 'user', 'guest']
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'environment',
|
|
54
|
+
systemType: 'literal',
|
|
55
|
+
configuration: {
|
|
56
|
+
enumeratedValues: ['production', 'integration', 'development', 'test', 'ephemeral']
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'currency',
|
|
61
|
+
systemType: 'literal',
|
|
62
|
+
configuration: {
|
|
63
|
+
caseSensitive: true,
|
|
64
|
+
enumeratedValues: ['USD', 'EUR', 'GBP', 'JPY', 'CNY']
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'market',
|
|
69
|
+
systemType: 'literal',
|
|
70
|
+
configuration: {
|
|
71
|
+
enumeratedValues: [
|
|
72
|
+
'world',
|
|
73
|
+
'americas',
|
|
74
|
+
'europe',
|
|
75
|
+
'asia',
|
|
76
|
+
'oceania',
|
|
77
|
+
'africa',
|
|
78
|
+
'middle-east',
|
|
79
|
+
'latin-america',
|
|
80
|
+
'caribbean',
|
|
81
|
+
'central-america',
|
|
82
|
+
'south-america',
|
|
83
|
+
'north-america',
|
|
84
|
+
'nordics',
|
|
85
|
+
'baltic',
|
|
86
|
+
'balkans',
|
|
87
|
+
'eastern-europe',
|
|
88
|
+
'western-europe',
|
|
89
|
+
'central-europe',
|
|
90
|
+
'eastern-africa',
|
|
91
|
+
'western-africa',
|
|
92
|
+
'central-africa',
|
|
93
|
+
'north-africa',
|
|
94
|
+
'south-africa',
|
|
95
|
+
'middle-africa',
|
|
96
|
+
'southeast-asia'
|
|
97
|
+
],
|
|
98
|
+
hierarchy: {
|
|
99
|
+
americas: 'world',
|
|
100
|
+
europe: 'world',
|
|
101
|
+
asia: 'world',
|
|
102
|
+
oceania: 'world',
|
|
103
|
+
africa: 'world',
|
|
104
|
+
'middle-east': 'world',
|
|
105
|
+
'latin-america': 'americas',
|
|
106
|
+
caribbean: 'americas',
|
|
107
|
+
'central-america': 'americas',
|
|
108
|
+
'south-america': 'americas',
|
|
109
|
+
'north-america': 'americas',
|
|
110
|
+
nordics: 'europe',
|
|
111
|
+
baltic: 'europe',
|
|
112
|
+
balkans: 'europe',
|
|
113
|
+
'eastern-europe': 'europe',
|
|
114
|
+
'western-europe': 'europe',
|
|
115
|
+
'central-europe': 'europe',
|
|
116
|
+
'eastern-africa': 'africa',
|
|
117
|
+
'western-africa': 'africa',
|
|
118
|
+
'central-africa': 'africa',
|
|
119
|
+
'north-africa': 'africa',
|
|
120
|
+
'south-africa': 'africa',
|
|
121
|
+
'middle-africa': 'africa',
|
|
122
|
+
'southeast-asia': 'asia'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* Example extended qualifiers.
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
exports.ExtendedQualifiers = [
|
|
132
|
+
{
|
|
133
|
+
name: 'homeTerritory',
|
|
134
|
+
token: 'home',
|
|
135
|
+
typeName: 'territory',
|
|
136
|
+
defaultPriority: 900
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'currentTerritory',
|
|
140
|
+
token: 'geo',
|
|
141
|
+
typeName: 'territory',
|
|
142
|
+
defaultPriority: 850
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: 'language',
|
|
146
|
+
token: 'lang',
|
|
147
|
+
typeName: 'language',
|
|
148
|
+
defaultPriority: 800
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: 'market',
|
|
152
|
+
typeName: 'market',
|
|
153
|
+
defaultPriority: 750
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'role',
|
|
157
|
+
typeName: 'role',
|
|
158
|
+
defaultPriority: 700
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: 'environment',
|
|
162
|
+
token: 'env',
|
|
163
|
+
typeName: 'environment',
|
|
164
|
+
defaultPriority: 650
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'currency',
|
|
168
|
+
typeName: 'currency',
|
|
169
|
+
defaultPriority: 600
|
|
170
|
+
}
|
|
171
|
+
];
|
|
172
|
+
/**
|
|
173
|
+
* Example resource types.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
exports.ExtendedResourceTypes = [
|
|
177
|
+
{
|
|
178
|
+
name: 'json',
|
|
179
|
+
typeName: 'json'
|
|
180
|
+
}
|
|
181
|
+
];
|
|
182
|
+
/**
|
|
183
|
+
* An example system configuration demonstrating various configuration options.
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
exports.ExtendedSystemConfiguration = {
|
|
187
|
+
name: 'extended-example',
|
|
188
|
+
description: 'An example system configuration demonstrating various configuration options',
|
|
189
|
+
qualifierTypes: [...exports.ExtendedQualifierTypes],
|
|
190
|
+
qualifiers: [...exports.ExtendedQualifiers],
|
|
191
|
+
resourceTypes: [...exports.ExtendedResourceTypes]
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=extended.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
30
|
+
}) : (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
o[k2] = m[k];
|
|
33
|
+
}));
|
|
34
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}) : function(o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
40
|
+
var ownKeys = function(o) {
|
|
41
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
42
|
+
var ar = [];
|
|
43
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
return ownKeys(o);
|
|
47
|
+
};
|
|
48
|
+
return function (mod) {
|
|
49
|
+
if (mod && mod.__esModule) return mod;
|
|
50
|
+
var result = {};
|
|
51
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
52
|
+
__setModuleDefault(result, mod);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.Example = exports.Default = void 0;
|
|
58
|
+
const Default = __importStar(require("./default"));
|
|
59
|
+
exports.Default = Default;
|
|
60
|
+
const Example = __importStar(require("./extended"));
|
|
61
|
+
exports.Example = Example;
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Result } from '@fgv/ts-utils';
|
|
2
|
+
import * as QualifierTypes from '../qualifier-types';
|
|
3
|
+
import * as ResourceTypes from '../resource-types';
|
|
4
|
+
import { QualifierType, ReadOnlyQualifierTypeCollector } from '../qualifier-types';
|
|
5
|
+
import { IReadOnlyQualifierCollector } from '../qualifiers';
|
|
6
|
+
import { ReadOnlyResourceTypeCollector, ResourceType } from '../resource-types';
|
|
7
|
+
import { ISystemConfiguration } from './json';
|
|
8
|
+
import { IConfigInitFactory } from './configInitFactory';
|
|
9
|
+
/**
|
|
10
|
+
* Parameters used to initialize a {@link Config.SystemConfiguration | SystemConfiguration}.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface ISystemConfigurationInitParams {
|
|
14
|
+
/**
|
|
15
|
+
* Optional map of qualifier names to default values. If provided, qualifiers
|
|
16
|
+
* in the system configuration will be updated with these default values.
|
|
17
|
+
* Use `null` as the value to remove an existing default value.
|
|
18
|
+
*/
|
|
19
|
+
qualifierDefaultValues?: Record<string, string | null>;
|
|
20
|
+
qualifierTypeFactory?: IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, QualifierType>;
|
|
21
|
+
resourceTypeFactory?: IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a copy of the provided {@link Config.Model.ISystemConfiguration | system configuration}
|
|
25
|
+
* with updated qualifier default values.
|
|
26
|
+
* @param config - The base {@link Config.Model.ISystemConfiguration | system configuration} to copy.
|
|
27
|
+
* @param qualifierDefaultValues - Map of qualifier names to default values. Use `null` to remove existing values.
|
|
28
|
+
* @returns `Success` with the updated {@link Config.Model.ISystemConfiguration | system configuration}
|
|
29
|
+
* if successful, `Failure` with an error message otherwise.
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare function updateSystemConfigurationQualifierDefaultValues(config: ISystemConfiguration, qualifierDefaultValues: Record<string, string | null>): Result<ISystemConfiguration>;
|
|
33
|
+
/**
|
|
34
|
+
* A system configuration for both runtime or build.
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export declare class SystemConfiguration {
|
|
38
|
+
/**
|
|
39
|
+
* The name of this system configuration.
|
|
40
|
+
*/
|
|
41
|
+
get name(): string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The description of this system configuration.
|
|
44
|
+
*/
|
|
45
|
+
get description(): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The {@link QualifierTypes.QualifierTypeCollector | qualifier types} that this system configuration uses.
|
|
48
|
+
*/
|
|
49
|
+
readonly qualifierTypes: ReadOnlyQualifierTypeCollector;
|
|
50
|
+
/**
|
|
51
|
+
* The {@link QualifierTypes.QualifierTypeCollector | qualifier types} that this system configuration uses.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
readonly qualifiers: IReadOnlyQualifierCollector;
|
|
55
|
+
/**
|
|
56
|
+
* The {@link ResourceTypes.ResourceTypeCollector | resource types} that this system configuration uses.
|
|
57
|
+
*/
|
|
58
|
+
readonly resourceTypes: ReadOnlyResourceTypeCollector;
|
|
59
|
+
private readonly _config;
|
|
60
|
+
/**
|
|
61
|
+
* Constructs a new instance of a {@link Config.SystemConfiguration | SystemConfiguration} from the
|
|
62
|
+
* supplied {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
63
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
protected constructor(config: ISystemConfiguration, initParams?: ISystemConfigurationInitParams);
|
|
67
|
+
/**
|
|
68
|
+
* Creates a new {@link Config.SystemConfiguration | SystemConfiguration} from the supplied
|
|
69
|
+
* {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
70
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
71
|
+
* @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
|
|
72
|
+
* @returns `Success` with the new {@link Config.SystemConfiguration | SystemConfiguration}
|
|
73
|
+
* if successful, `Failure` with an error message otherwise.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
static create(config: ISystemConfiguration, initParams?: ISystemConfigurationInitParams): Result<SystemConfiguration>;
|
|
77
|
+
/**
|
|
78
|
+
* Loads a {@link Config.SystemConfiguration | SystemConfiguration} from a file.
|
|
79
|
+
* @param path - The path to the file to load.
|
|
80
|
+
* @returns `Success` with the {@link Config.SystemConfiguration | SystemConfiguration}
|
|
81
|
+
* if successful, `Failure` with an error message otherwise.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
static loadFromFile(path: string, initParams?: ISystemConfigurationInitParams): Result<SystemConfiguration>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the {@link Config.Model.ISystemConfiguration | system configuration} that this
|
|
87
|
+
* {@link Config.SystemConfiguration | SystemConfiguration} was created from.
|
|
88
|
+
* @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}
|
|
89
|
+
* if successful, `Failure` with an error message otherwise.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
getConfig(): Result<ISystemConfiguration>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=systemConfiguration.d.ts.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025 Erik Fortune
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
* furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
* copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
* SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.SystemConfiguration = void 0;
|
|
25
|
+
exports.updateSystemConfigurationQualifierDefaultValues = updateSystemConfigurationQualifierDefaultValues;
|
|
26
|
+
const ts_utils_1 = require("@fgv/ts-utils");
|
|
27
|
+
const qualifier_types_1 = require("../qualifier-types");
|
|
28
|
+
const qualifiers_1 = require("../qualifiers");
|
|
29
|
+
const resource_types_1 = require("../resource-types");
|
|
30
|
+
const convert_1 = require("./convert");
|
|
31
|
+
const ts_json_base_1 = require("@fgv/ts-json-base");
|
|
32
|
+
const configInitFactory_1 = require("./configInitFactory");
|
|
33
|
+
/**
|
|
34
|
+
* Creates a copy of the provided {@link Config.Model.ISystemConfiguration | system configuration}
|
|
35
|
+
* with updated qualifier default values.
|
|
36
|
+
* @param config - The base {@link Config.Model.ISystemConfiguration | system configuration} to copy.
|
|
37
|
+
* @param qualifierDefaultValues - Map of qualifier names to default values. Use `null` to remove existing values.
|
|
38
|
+
* @returns `Success` with the updated {@link Config.Model.ISystemConfiguration | system configuration}
|
|
39
|
+
* if successful, `Failure` with an error message otherwise.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
function updateSystemConfigurationQualifierDefaultValues(config, qualifierDefaultValues // eslint-disable-line @rushstack/no-new-null
|
|
43
|
+
) {
|
|
44
|
+
// Create a copy of the config
|
|
45
|
+
return (0, ts_json_base_1.sanitizeJsonObject)(config).onSuccess((updatedConfig) => {
|
|
46
|
+
// Create a map of existing qualifier names for validation
|
|
47
|
+
const existingQualifierNames = new Set(updatedConfig.qualifiers.map((q) => q.name));
|
|
48
|
+
// Validate that all specified qualifiers exist in the configuration
|
|
49
|
+
for (const qualifierName of Object.keys(qualifierDefaultValues)) {
|
|
50
|
+
if (!existingQualifierNames.has(qualifierName)) {
|
|
51
|
+
return (0, ts_utils_1.fail)(`Qualifier '${qualifierName}' not found in system configuration`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Update qualifier default values
|
|
55
|
+
updatedConfig.qualifiers = updatedConfig.qualifiers.map((qualifier) => {
|
|
56
|
+
if (qualifier.name in qualifierDefaultValues) {
|
|
57
|
+
const newDefaultValue = qualifierDefaultValues[qualifier.name];
|
|
58
|
+
// Create a copy of the qualifier
|
|
59
|
+
const updatedQualifier = Object.assign({}, qualifier);
|
|
60
|
+
if (newDefaultValue === null) {
|
|
61
|
+
// Remove the default value
|
|
62
|
+
delete updatedQualifier.defaultValue;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Set the new default value
|
|
66
|
+
updatedQualifier.defaultValue = newDefaultValue;
|
|
67
|
+
}
|
|
68
|
+
return updatedQualifier;
|
|
69
|
+
}
|
|
70
|
+
return qualifier;
|
|
71
|
+
});
|
|
72
|
+
return (0, ts_utils_1.succeed)(updatedConfig);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A system configuration for both runtime or build.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
class SystemConfiguration {
|
|
80
|
+
/**
|
|
81
|
+
* The name of this system configuration.
|
|
82
|
+
*/
|
|
83
|
+
get name() {
|
|
84
|
+
return this._config.name;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The description of this system configuration.
|
|
88
|
+
*/
|
|
89
|
+
get description() {
|
|
90
|
+
return this._config.description;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Constructs a new instance of a {@link Config.SystemConfiguration | SystemConfiguration} from the
|
|
94
|
+
* supplied {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
95
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
constructor(config, initParams) {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
this._config = config;
|
|
101
|
+
const qualifierTypeFactory = (_a = initParams === null || initParams === void 0 ? void 0 : initParams.qualifierTypeFactory) !== null && _a !== void 0 ? _a : new configInitFactory_1.BuiltInQualifierTypeFactory();
|
|
102
|
+
const resourceTypeFactory = (_b = initParams === null || initParams === void 0 ? void 0 : initParams.resourceTypeFactory) !== null && _b !== void 0 ? _b : new configInitFactory_1.BuiltInResourceTypeFactory();
|
|
103
|
+
this.qualifierTypes = qualifier_types_1.QualifierTypeCollector.create({
|
|
104
|
+
qualifierTypes: (0, ts_utils_1.mapResults)(config.qualifierTypes.map((tc) => qualifierTypeFactory.create(tc))).orThrow()
|
|
105
|
+
}).orThrow();
|
|
106
|
+
this.qualifiers = qualifiers_1.QualifierCollector.create({
|
|
107
|
+
qualifierTypes: this.qualifierTypes,
|
|
108
|
+
qualifiers: config.qualifiers
|
|
109
|
+
}).orThrow();
|
|
110
|
+
this.resourceTypes = resource_types_1.ResourceTypeCollector.create({
|
|
111
|
+
resourceTypes: (0, ts_utils_1.mapResults)(config.resourceTypes.map((rt) => resourceTypeFactory.create(rt))).orThrow()
|
|
112
|
+
}).orThrow();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new {@link Config.SystemConfiguration | SystemConfiguration} from the supplied
|
|
116
|
+
* {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
117
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
118
|
+
* @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
|
|
119
|
+
* @returns `Success` with the new {@link Config.SystemConfiguration | SystemConfiguration}
|
|
120
|
+
* if successful, `Failure` with an error message otherwise.
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
static create(config, initParams) {
|
|
124
|
+
if (initParams === null || initParams === void 0 ? void 0 : initParams.qualifierDefaultValues) {
|
|
125
|
+
/* c8 ignore next 9 - functional code tested but coverage intermittently missed */
|
|
126
|
+
return updateSystemConfigurationQualifierDefaultValues(config, initParams.qualifierDefaultValues).onSuccess((updatedConfig) => (0, ts_utils_1.captureResult)(() => new SystemConfiguration(updatedConfig, (0, ts_utils_1.omit)(initParams, ['qualifierDefaultValues']))));
|
|
127
|
+
}
|
|
128
|
+
return (0, ts_utils_1.captureResult)(() => new SystemConfiguration(config, initParams));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Loads a {@link Config.SystemConfiguration | SystemConfiguration} from a file.
|
|
132
|
+
* @param path - The path to the file to load.
|
|
133
|
+
* @returns `Success` with the {@link Config.SystemConfiguration | SystemConfiguration}
|
|
134
|
+
* if successful, `Failure` with an error message otherwise.
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
static loadFromFile(path, initParams) {
|
|
138
|
+
return ts_json_base_1.JsonFile.convertJsonFileSync(path, convert_1.systemConfiguration).onSuccess((config) => SystemConfiguration.create(config, initParams));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns the {@link Config.Model.ISystemConfiguration | system configuration} that this
|
|
142
|
+
* {@link Config.SystemConfiguration | SystemConfiguration} was created from.
|
|
143
|
+
* @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}
|
|
144
|
+
* if successful, `Failure` with an error message otherwise.
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
getConfig() {
|
|
148
|
+
return convert_1.systemConfiguration.convert(this._config);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.SystemConfiguration = SystemConfiguration;
|
|
152
|
+
//# sourceMappingURL=systemConfiguration.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Converter } from '@fgv/ts-utils';
|
|
2
|
+
import * as Model from './json';
|
|
3
|
+
import { Converters as JsonConverters } from '@fgv/ts-json-base';
|
|
4
|
+
/**
|
|
5
|
+
* A `Converter` for {@link QualifierTypes.Config.ILanguageQualifierTypeConfig | LanguageQualifierTypeConfig} objects.
|
|
6
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ILanguageQualifierTypeConfig | LanguageQualifierTypeConfig} objects.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare const languageQualifierTypeConfig: import("@fgv/ts-utils").ObjectConverter<Model.ILanguageQualifierTypeConfig, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* A `Converter` for {@link QualifierTypes.Config.ITerritoryQualifierTypeConfig | TerritoryQualifierTypeConfig} objects.
|
|
12
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ITerritoryQualifierTypeConfig | TerritoryQualifierTypeConfig} objects.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare const territoryQualifierTypeConfig: import("@fgv/ts-utils").ObjectConverter<Model.ITerritoryQualifierTypeConfig, unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* A `Converter` for {@link QualifierTypes.Config.ILiteralQualifierTypeConfig | LiteralQualifierTypeConfig} objects.
|
|
18
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ILiteralQualifierTypeConfig | LiteralQualifierTypeConfig} objects.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare const literalQualifierTypeConfig: import("@fgv/ts-utils").ObjectConverter<Model.ILiteralQualifierTypeConfig, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* A `Converter` for {@link QualifierTypes.Config.ISystemLanguageQualifierTypeConfig | SystemLanguageQualifierTypeConfig} objects.
|
|
24
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ISystemLanguageQualifierTypeConfig | SystemLanguageQualifierTypeConfig} objects.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare const systemLanguageQualifierTypeConfig: import("@fgv/ts-utils").ObjectConverter<Model.ISystemLanguageQualifierTypeConfig, unknown>;
|
|
28
|
+
/**
|
|
29
|
+
* A `Converter` for {@link QualifierTypes.Config.ISystemTerritoryQualifierTypeConfig | SystemTerritoryQualifierTypeConfig} objects.
|
|
30
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ISystemTerritoryQualifierTypeConfig | SystemTerritoryQualifierTypeConfig} objects.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export declare const systemTerritoryQualifierTypeConfig: import("@fgv/ts-utils").ObjectConverter<Model.ISystemTerritoryQualifierTypeConfig, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* A `Converter` for {@link QualifierTypes.Config.ISystemLiteralQualifierTypeConfig | SystemLiteralQualifierTypeConfig} objects.
|
|
36
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ISystemLiteralQualifierTypeConfig | SystemLiteralQualifierTypeConfig} objects.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare const systemLiteralQualifierTypeConfig: import("@fgv/ts-utils").ObjectConverter<Model.ISystemLiteralQualifierTypeConfig, unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* A `Converter` for {@link QualifierTypes.Config.ISystemQualifierTypeConfig | SystemQualifierTypeConfig} objects.
|
|
42
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.ISystemQualifierTypeConfig | SystemQualifierTypeConfig} objects.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
export declare const systemQualifierTypeConfig: Converter<Model.ISystemQualifierTypeConfig, unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* A `Converter` for {@link QualifierTypes.Config.IQualifierTypeConfig | QualifierTypeConfig} objects.
|
|
48
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.IQualifierTypeConfig | QualifierTypeConfig} objects.
|
|
49
|
+
* @param config - A `Converter` for the configuration object.
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export declare function qualifierTypeConfig<T, TD = unknown>(config: Converter<T, TD>): Converter<Model.IQualifierTypeConfig<T>, TD>;
|
|
53
|
+
/**
|
|
54
|
+
* A `Converter` for {@link QualifierTypes.Config.IQualifierTypeConfig | QualifierTypeConfig} objects.
|
|
55
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.IQualifierTypeConfig | QualifierTypeConfig} objects.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
export declare const jsonQualifierTypeConfig: Converter<Model.IQualifierTypeConfig<import("@fgv/ts-json-base").JsonObject>, JsonConverters.IJsonConverterContext>;
|
|
59
|
+
/**
|
|
60
|
+
* A `Converter` for {@link QualifierTypes.Config.IAnyQualifierTypeConfig | AnyQualifierTypeConfig} objects.
|
|
61
|
+
* @returns A `Converter` for {@link QualifierTypes.Config.IAnyQualifierTypeConfig | AnyQualifierTypeConfig} objects.
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export declare const anyQualifierTypeConfig: Converter<Model.IAnyQualifierTypeConfig, unknown>;
|
|
65
|
+
//# sourceMappingURL=convert.d.ts.map
|