@fgv/ts-res 5.0.1-8 → 5.0.1
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/index.browser.js +53 -0
- package/dist/index.js +45 -0
- package/dist/packlets/bundle/bundleBuilder.js +130 -0
- package/dist/packlets/bundle/bundleLoader.js +101 -0
- package/dist/packlets/bundle/bundleNormalizer.js +138 -0
- package/dist/packlets/bundle/bundleUtils.js +113 -0
- package/dist/packlets/bundle/convert.js +75 -0
- package/dist/packlets/bundle/index.js +42 -0
- package/dist/packlets/bundle/model.js +23 -0
- package/dist/packlets/common/conditions.js +47 -0
- package/dist/packlets/common/convert.js +172 -0
- package/dist/packlets/common/helpers/conditions.js +66 -0
- package/dist/packlets/common/helpers/context.js +70 -0
- package/dist/packlets/common/helpers/index.js +26 -0
- package/dist/packlets/common/helpers/qualifierDefaultValues.js +66 -0
- package/dist/packlets/common/helpers/resources.js +93 -0
- package/dist/packlets/common/index.js +28 -0
- package/dist/packlets/common/resources.js +27 -0
- package/dist/packlets/common/validate/conditions.js +544 -0
- package/dist/packlets/common/validate/index.js +26 -0
- package/dist/packlets/common/validate/regularExpressions.js +84 -0
- package/dist/packlets/common/validate/resources.js +209 -0
- package/dist/packlets/conditions/condition.js +252 -0
- package/dist/packlets/conditions/conditionCollector.js +69 -0
- package/dist/packlets/conditions/conditionDecls.js +23 -0
- package/dist/packlets/conditions/conditionSet.js +247 -0
- package/dist/packlets/conditions/conditionSetCollector.js +89 -0
- package/dist/packlets/conditions/conditionSetDecls.js +23 -0
- package/dist/packlets/conditions/conditionToken.js +147 -0
- package/dist/packlets/conditions/convert/conditionSetDecls.js +51 -0
- package/dist/packlets/conditions/convert/decls.js +75 -0
- package/dist/packlets/conditions/convert/index.js +24 -0
- package/dist/packlets/conditions/index.js +31 -0
- 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/context/contextDecls.js +23 -0
- package/dist/packlets/context/contextToken.js +202 -0
- package/dist/packlets/context/convert/decls.js +91 -0
- package/dist/packlets/context/convert/index.js +23 -0
- package/dist/packlets/context/index.js +26 -0
- package/dist/packlets/decisions/abstractDecision.js +68 -0
- package/dist/packlets/decisions/abstractDecisionCollector.js +90 -0
- package/dist/packlets/decisions/candidate.js +76 -0
- package/dist/packlets/decisions/common.js +23 -0
- package/dist/packlets/decisions/concreteDecision.js +111 -0
- package/dist/packlets/decisions/decision.js +126 -0
- package/dist/packlets/decisions/index.js +28 -0
- package/dist/packlets/import/fsItem.js +134 -0
- package/dist/packlets/import/importContext.js +129 -0
- package/dist/packlets/import/importManager.js +129 -0
- package/dist/packlets/import/importable.js +32 -0
- package/dist/packlets/import/importers/collectionImporter.js +118 -0
- package/dist/packlets/import/importers/fsItemImporter.js +116 -0
- package/dist/packlets/import/importers/importer.js +23 -0
- package/dist/packlets/import/importers/index.browser.js +29 -0
- package/dist/packlets/import/importers/index.js +27 -0
- package/dist/packlets/import/importers/jsonImporter.js +94 -0
- package/dist/packlets/import/importers/pathImporter.js +84 -0
- package/dist/packlets/import/index.browser.js +34 -0
- package/dist/packlets/import/index.js +28 -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/qualifier-types/convert.js +56 -0
- package/dist/packlets/qualifier-types/helpers.js +82 -0
- package/dist/packlets/qualifier-types/index.js +32 -0
- package/dist/packlets/qualifier-types/languageQualifierType.js +142 -0
- package/dist/packlets/qualifier-types/literalQualifierType.js +200 -0
- package/dist/packlets/qualifier-types/literalValueHierarchy.js +236 -0
- package/dist/packlets/qualifier-types/qualifierType.js +184 -0
- package/dist/packlets/qualifier-types/qualifierTypeCollector.js +66 -0
- package/dist/packlets/qualifier-types/territoryQualifierType.js +200 -0
- package/dist/packlets/qualifiers/convert/decls.js +70 -0
- package/dist/packlets/qualifiers/convert/index.js +24 -0
- package/dist/packlets/qualifiers/convert/qualifier.js +40 -0
- package/dist/packlets/qualifiers/index.js +29 -0
- package/dist/packlets/qualifiers/qualifier.js +108 -0
- package/dist/packlets/qualifiers/qualifierCollector.js +123 -0
- package/dist/packlets/qualifiers/qualifierDecl.js +23 -0
- package/dist/packlets/qualifiers/qualifierDefaultValueDecls.js +23 -0
- package/dist/packlets/qualifiers/qualifierDefaultValueToken.js +175 -0
- package/dist/packlets/resource-json/compiled/common.js +23 -0
- package/dist/packlets/resource-json/compiled/convert.js +132 -0
- package/dist/packlets/resource-json/compiled/index.js +26 -0
- package/dist/packlets/resource-json/compiled/json.js +2 -0
- package/dist/packlets/resource-json/convert.js +171 -0
- package/dist/packlets/resource-json/helpers.js +241 -0
- package/dist/packlets/resource-json/index.js +31 -0
- package/dist/packlets/resource-json/json.js +36 -0
- package/dist/packlets/resource-json/normalized.js +23 -0
- package/dist/packlets/resource-json/resourceDeclCollection.js +88 -0
- package/dist/packlets/resource-json/resourceDeclContainer.js +23 -0
- package/dist/packlets/resource-json/resourceDeclTree.js +94 -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/packlets/resource-types/helpers.js +42 -0
- package/dist/packlets/resource-types/index.js +28 -0
- package/dist/packlets/resource-types/jsonResourceType.js +66 -0
- package/dist/packlets/resource-types/resourceType.js +95 -0
- package/dist/packlets/resource-types/resourceTypeCollector.js +61 -0
- package/dist/packlets/resources/candidateReducer.js +246 -0
- package/dist/packlets/resources/candidateValue.js +92 -0
- package/dist/packlets/resources/candidateValueCollector.js +94 -0
- package/dist/packlets/resources/common.js +23 -0
- package/dist/packlets/resources/deltaGenerator.js +338 -0
- package/dist/packlets/resources/index.js +31 -0
- package/dist/packlets/resources/resource.js +207 -0
- package/dist/packlets/resources/resourceBuilder.js +183 -0
- package/dist/packlets/resources/resourceCandidate.js +216 -0
- package/dist/packlets/resources/resourceManagerBuilder.js +890 -0
- package/dist/packlets/runtime/cacheListener.js +58 -0
- package/dist/packlets/runtime/cacheMetrics.js +149 -0
- package/dist/packlets/runtime/compiledResourceCollection.js +473 -0
- package/dist/packlets/runtime/conditionSetResolutionResult.js +134 -0
- package/dist/packlets/runtime/context/contextQualifierProvider.js +29 -0
- package/dist/packlets/runtime/context/contextQualifierProviderValidator.js +146 -0
- package/dist/packlets/runtime/context/index.js +26 -0
- package/dist/packlets/runtime/context/simpleContextQualifierProvider.js +196 -0
- package/dist/packlets/runtime/context/validatingSimpleContextQualifierProvider.js +60 -0
- package/dist/packlets/runtime/iResourceManager.js +23 -0
- package/dist/packlets/runtime/index.js +34 -0
- package/dist/packlets/runtime/resource-tree/common.js +23 -0
- package/dist/packlets/runtime/resource-tree/index.js +26 -0
- package/dist/packlets/runtime/resource-tree/readOnlyResourceTree.js +216 -0
- package/dist/packlets/runtime/resource-tree/resourceTreeChildren.js +97 -0
- package/dist/packlets/runtime/resource-tree/resourceTreeChildrenValidator.js +161 -0
- package/dist/packlets/runtime/resourceResolver.js +481 -0
- package/dist/packlets/runtime/resourceTreeResolver.js +220 -0
- package/dist/packlets/runtime/validate.js +47 -0
- package/dist/packlets/zip-archive/convert.js +100 -0
- package/dist/packlets/zip-archive/index.browser.js +54 -0
- package/dist/packlets/zip-archive/index.js +47 -0
- package/dist/packlets/zip-archive/json.js +23 -0
- package/dist/packlets/zip-archive/types.js +36 -0
- package/dist/packlets/zip-archive/zipArchiveCreator.js +191 -0
- package/dist/packlets/zip-archive/zipArchiveFormat.js +140 -0
- package/dist/packlets/zip-archive/zipArchiveLoader.js +282 -0
- package/dist/test/data/sample.json +32 -0
- package/dist/test/unit/qualifier-types/testQualifierType.js +76 -0
- package/dist/test/unit/resource-types/testDerivedResourceType.js +109 -0
- package/dist/test/unit/resources/deltaGenerator.helpers.js +282 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/index.browser.d.ts +24 -0
- package/lib/index.browser.js +116 -0
- package/lib/packlets/config/index.browser.d.ts +7 -0
- package/lib/packlets/config/index.browser.js +74 -0
- package/lib/packlets/import/importers/index.browser.d.ts +4 -0
- package/lib/packlets/import/importers/index.browser.js +45 -0
- package/lib/packlets/import/index.browser.d.ts +7 -0
- package/lib/packlets/import/index.browser.js +74 -0
- package/lib/packlets/zip-archive/index.browser.d.ts +27 -0
- package/lib/packlets/zip-archive/index.browser.js +102 -0
- package/package.json +21 -7
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Example extended qualifier types.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export const ExtendedQualifierTypes = [
|
|
27
|
+
{
|
|
28
|
+
name: 'language',
|
|
29
|
+
systemType: 'language',
|
|
30
|
+
configuration: {
|
|
31
|
+
allowContextList: true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'territory',
|
|
36
|
+
systemType: 'territory',
|
|
37
|
+
configuration: {
|
|
38
|
+
allowContextList: false,
|
|
39
|
+
acceptLowercase: false
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'role',
|
|
44
|
+
systemType: 'literal',
|
|
45
|
+
configuration: {
|
|
46
|
+
enumeratedValues: ['admin', 'agent', 'user', 'guest']
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'environment',
|
|
51
|
+
systemType: 'literal',
|
|
52
|
+
configuration: {
|
|
53
|
+
enumeratedValues: ['production', 'integration', 'development', 'test', 'ephemeral']
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'currency',
|
|
58
|
+
systemType: 'literal',
|
|
59
|
+
configuration: {
|
|
60
|
+
caseSensitive: true,
|
|
61
|
+
enumeratedValues: ['USD', 'EUR', 'GBP', 'JPY', 'CNY']
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'market',
|
|
66
|
+
systemType: 'literal',
|
|
67
|
+
configuration: {
|
|
68
|
+
enumeratedValues: [
|
|
69
|
+
'world',
|
|
70
|
+
'americas',
|
|
71
|
+
'europe',
|
|
72
|
+
'asia',
|
|
73
|
+
'oceania',
|
|
74
|
+
'africa',
|
|
75
|
+
'middle-east',
|
|
76
|
+
'latin-america',
|
|
77
|
+
'caribbean',
|
|
78
|
+
'central-america',
|
|
79
|
+
'south-america',
|
|
80
|
+
'north-america',
|
|
81
|
+
'nordics',
|
|
82
|
+
'baltic',
|
|
83
|
+
'balkans',
|
|
84
|
+
'eastern-europe',
|
|
85
|
+
'western-europe',
|
|
86
|
+
'central-europe',
|
|
87
|
+
'eastern-africa',
|
|
88
|
+
'western-africa',
|
|
89
|
+
'central-africa',
|
|
90
|
+
'north-africa',
|
|
91
|
+
'south-africa',
|
|
92
|
+
'middle-africa',
|
|
93
|
+
'southeast-asia'
|
|
94
|
+
],
|
|
95
|
+
hierarchy: {
|
|
96
|
+
americas: 'world',
|
|
97
|
+
europe: 'world',
|
|
98
|
+
asia: 'world',
|
|
99
|
+
oceania: 'world',
|
|
100
|
+
africa: 'world',
|
|
101
|
+
'middle-east': 'world',
|
|
102
|
+
'latin-america': 'americas',
|
|
103
|
+
caribbean: 'americas',
|
|
104
|
+
'central-america': 'americas',
|
|
105
|
+
'south-america': 'americas',
|
|
106
|
+
'north-america': 'americas',
|
|
107
|
+
nordics: 'europe',
|
|
108
|
+
baltic: 'europe',
|
|
109
|
+
balkans: 'europe',
|
|
110
|
+
'eastern-europe': 'europe',
|
|
111
|
+
'western-europe': 'europe',
|
|
112
|
+
'central-europe': 'europe',
|
|
113
|
+
'eastern-africa': 'africa',
|
|
114
|
+
'western-africa': 'africa',
|
|
115
|
+
'central-africa': 'africa',
|
|
116
|
+
'north-africa': 'africa',
|
|
117
|
+
'south-africa': 'africa',
|
|
118
|
+
'middle-africa': 'africa',
|
|
119
|
+
'southeast-asia': 'asia'
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
/**
|
|
125
|
+
* Example extended qualifiers.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export const ExtendedQualifiers = [
|
|
129
|
+
{
|
|
130
|
+
name: 'homeTerritory',
|
|
131
|
+
token: 'home',
|
|
132
|
+
typeName: 'territory',
|
|
133
|
+
defaultPriority: 900
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: 'currentTerritory',
|
|
137
|
+
token: 'geo',
|
|
138
|
+
typeName: 'territory',
|
|
139
|
+
defaultPriority: 850
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'language',
|
|
143
|
+
token: 'lang',
|
|
144
|
+
typeName: 'language',
|
|
145
|
+
defaultPriority: 800
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'market',
|
|
149
|
+
typeName: 'market',
|
|
150
|
+
defaultPriority: 750
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'role',
|
|
154
|
+
typeName: 'role',
|
|
155
|
+
defaultPriority: 700
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'environment',
|
|
159
|
+
token: 'env',
|
|
160
|
+
typeName: 'environment',
|
|
161
|
+
defaultPriority: 650
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'currency',
|
|
165
|
+
typeName: 'currency',
|
|
166
|
+
defaultPriority: 600
|
|
167
|
+
}
|
|
168
|
+
];
|
|
169
|
+
/**
|
|
170
|
+
* Example resource types.
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
export const ExtendedResourceTypes = [
|
|
174
|
+
{
|
|
175
|
+
name: 'json',
|
|
176
|
+
typeName: 'json'
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
/**
|
|
180
|
+
* An example system configuration demonstrating various configuration options.
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
export const ExtendedSystemConfiguration = {
|
|
184
|
+
name: 'extended-example',
|
|
185
|
+
description: 'An example system configuration demonstrating various configuration options',
|
|
186
|
+
qualifierTypes: [...ExtendedQualifierTypes],
|
|
187
|
+
qualifiers: [...ExtendedQualifiers],
|
|
188
|
+
resourceTypes: [...ExtendedResourceTypes]
|
|
189
|
+
};
|
|
190
|
+
//# sourceMappingURL=extended.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import * as Default from './default';
|
|
23
|
+
import * as Example from './extended';
|
|
24
|
+
export { Default, Example };
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { captureResult, mapResults, fail, succeed, omit } from '@fgv/ts-utils';
|
|
23
|
+
import { QualifierTypeCollector } from '../qualifier-types';
|
|
24
|
+
import { QualifierCollector } from '../qualifiers';
|
|
25
|
+
import { ResourceTypeCollector } from '../resource-types';
|
|
26
|
+
import { systemConfiguration } from './convert';
|
|
27
|
+
import { JsonFile, sanitizeJsonObject } from '@fgv/ts-json-base';
|
|
28
|
+
import { BuiltInQualifierTypeFactory, BuiltInResourceTypeFactory } from './configInitFactory';
|
|
29
|
+
/**
|
|
30
|
+
* Creates a copy of the provided {@link Config.Model.ISystemConfiguration | system configuration}
|
|
31
|
+
* with updated qualifier default values.
|
|
32
|
+
* @param config - The base {@link Config.Model.ISystemConfiguration | system configuration} to copy.
|
|
33
|
+
* @param qualifierDefaultValues - Map of qualifier names to default values. Use `null` to remove existing values.
|
|
34
|
+
* @returns `Success` with the updated {@link Config.Model.ISystemConfiguration | system configuration}
|
|
35
|
+
* if successful, `Failure` with an error message otherwise.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export function updateSystemConfigurationQualifierDefaultValues(config, qualifierDefaultValues // eslint-disable-line @rushstack/no-new-null
|
|
39
|
+
) {
|
|
40
|
+
// Create a copy of the config
|
|
41
|
+
return sanitizeJsonObject(config).onSuccess((updatedConfig) => {
|
|
42
|
+
// Create a map of existing qualifier names for validation
|
|
43
|
+
const existingQualifierNames = new Set(updatedConfig.qualifiers.map((q) => q.name));
|
|
44
|
+
// Validate that all specified qualifiers exist in the configuration
|
|
45
|
+
for (const qualifierName of Object.keys(qualifierDefaultValues)) {
|
|
46
|
+
if (!existingQualifierNames.has(qualifierName)) {
|
|
47
|
+
return fail(`Qualifier '${qualifierName}' not found in system configuration`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Update qualifier default values
|
|
51
|
+
updatedConfig.qualifiers = updatedConfig.qualifiers.map((qualifier) => {
|
|
52
|
+
if (qualifier.name in qualifierDefaultValues) {
|
|
53
|
+
const newDefaultValue = qualifierDefaultValues[qualifier.name];
|
|
54
|
+
// Create a copy of the qualifier
|
|
55
|
+
const updatedQualifier = Object.assign({}, qualifier);
|
|
56
|
+
if (newDefaultValue === null) {
|
|
57
|
+
// Remove the default value
|
|
58
|
+
delete updatedQualifier.defaultValue;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Set the new default value
|
|
62
|
+
updatedQualifier.defaultValue = newDefaultValue;
|
|
63
|
+
}
|
|
64
|
+
return updatedQualifier;
|
|
65
|
+
}
|
|
66
|
+
return qualifier;
|
|
67
|
+
});
|
|
68
|
+
return succeed(updatedConfig);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A system configuration for both runtime or build.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export class SystemConfiguration {
|
|
76
|
+
/**
|
|
77
|
+
* The name of this system configuration.
|
|
78
|
+
*/
|
|
79
|
+
get name() {
|
|
80
|
+
return this._config.name;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The description of this system configuration.
|
|
84
|
+
*/
|
|
85
|
+
get description() {
|
|
86
|
+
return this._config.description;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Constructs a new instance of a {@link Config.SystemConfiguration | SystemConfiguration} from the
|
|
90
|
+
* supplied {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
91
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
constructor(config, initParams) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
this._config = config;
|
|
97
|
+
const qualifierTypeFactory = (_a = initParams === null || initParams === void 0 ? void 0 : initParams.qualifierTypeFactory) !== null && _a !== void 0 ? _a : new BuiltInQualifierTypeFactory();
|
|
98
|
+
const resourceTypeFactory = (_b = initParams === null || initParams === void 0 ? void 0 : initParams.resourceTypeFactory) !== null && _b !== void 0 ? _b : new BuiltInResourceTypeFactory();
|
|
99
|
+
this.qualifierTypes = QualifierTypeCollector.create({
|
|
100
|
+
qualifierTypes: mapResults(config.qualifierTypes.map((tc) => qualifierTypeFactory.create(tc))).orThrow()
|
|
101
|
+
}).orThrow();
|
|
102
|
+
this.qualifiers = QualifierCollector.create({
|
|
103
|
+
qualifierTypes: this.qualifierTypes,
|
|
104
|
+
qualifiers: config.qualifiers
|
|
105
|
+
}).orThrow();
|
|
106
|
+
this.resourceTypes = ResourceTypeCollector.create({
|
|
107
|
+
resourceTypes: mapResults(config.resourceTypes.map((rt) => resourceTypeFactory.create(rt))).orThrow()
|
|
108
|
+
}).orThrow();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Creates a new {@link Config.SystemConfiguration | SystemConfiguration} from the supplied
|
|
112
|
+
* {@link Config.Model.ISystemConfiguration | system configuration}.
|
|
113
|
+
* @param config - The {@link Config.Model.ISystemConfiguration | system configuration} to use.
|
|
114
|
+
* @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
|
|
115
|
+
* @returns `Success` with the new {@link Config.SystemConfiguration | SystemConfiguration}
|
|
116
|
+
* if successful, `Failure` with an error message otherwise.
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
static create(config, initParams) {
|
|
120
|
+
if (initParams === null || initParams === void 0 ? void 0 : initParams.qualifierDefaultValues) {
|
|
121
|
+
/* c8 ignore next 9 - functional code tested but coverage intermittently missed */
|
|
122
|
+
return updateSystemConfigurationQualifierDefaultValues(config, initParams.qualifierDefaultValues).onSuccess((updatedConfig) => captureResult(() => new SystemConfiguration(updatedConfig, omit(initParams, ['qualifierDefaultValues']))));
|
|
123
|
+
}
|
|
124
|
+
return captureResult(() => new SystemConfiguration(config, initParams));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Loads a {@link Config.SystemConfiguration | SystemConfiguration} from a file.
|
|
128
|
+
* @param path - The path to the file to load.
|
|
129
|
+
* @returns `Success` with the {@link Config.SystemConfiguration | SystemConfiguration}
|
|
130
|
+
* if successful, `Failure` with an error message otherwise.
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
static loadFromFile(path, initParams) {
|
|
134
|
+
return JsonFile.convertJsonFileSync(path, systemConfiguration).onSuccess((config) => SystemConfiguration.create(config, initParams));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Returns the {@link Config.Model.ISystemConfiguration | system configuration} that this
|
|
138
|
+
* {@link Config.SystemConfiguration | SystemConfiguration} was created from.
|
|
139
|
+
* @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}
|
|
140
|
+
* if successful, `Failure` with an error message otherwise.
|
|
141
|
+
* @public
|
|
142
|
+
*/
|
|
143
|
+
getConfig() {
|
|
144
|
+
return systemConfiguration.convert(this._config);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=systemConfiguration.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=contextDecls.js.map
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { mapResults, fail, succeed } from '@fgv/ts-utils';
|
|
23
|
+
import { Helpers as CommonHelpers } from '../common';
|
|
24
|
+
/**
|
|
25
|
+
* Helper class to parse and validate context tokens.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export class ContextTokens {
|
|
29
|
+
/**
|
|
30
|
+
* Constructs a new {@link Context.ContextTokens | ContextTokens } instance.
|
|
31
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
32
|
+
*/
|
|
33
|
+
constructor(qualifiers) {
|
|
34
|
+
this.qualifiers = qualifiers;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Parses a {@link ContextQualifierToken | context qualifier token} string and validates the parts
|
|
38
|
+
* against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.
|
|
39
|
+
* @param token - the token string to parse.
|
|
40
|
+
* @returns `Success` with the {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration}
|
|
41
|
+
* if successful, `Failure` with an error message if not.
|
|
42
|
+
*/
|
|
43
|
+
parseContextQualifierToken(token) {
|
|
44
|
+
return ContextTokens.parseContextQualifierToken(token, this.qualifiers);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parses a {@link ContextToken | context token} string and validates the parts
|
|
48
|
+
* against the qualifiers present in the {@link Context.ContextTokens.qualifiers | qualifier collector}.
|
|
49
|
+
* @param token - the token string to parse.
|
|
50
|
+
* @returns `Success` with the array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}
|
|
51
|
+
* if successful, `Failure` with an error message if not.
|
|
52
|
+
*/
|
|
53
|
+
parseContextToken(token) {
|
|
54
|
+
return ContextTokens.parseContextToken(token, this.qualifiers);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validates the {@link Helpers.IContextTokenParts | parts} of a {@link ContextToken | context token}.
|
|
58
|
+
* @param parts - the parts to validate
|
|
59
|
+
* @returns `Success` with the validated declaration if successful, `Failure` with an error message if not.
|
|
60
|
+
*/
|
|
61
|
+
validateContextTokenParts(parts) {
|
|
62
|
+
return ContextTokens.validateContextTokenParts(parts, this.qualifiers);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Given a value, finds a single token-optional qualifier that matches the value.
|
|
66
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
67
|
+
* @param value - the value to match.
|
|
68
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
69
|
+
*/
|
|
70
|
+
findQualifierForValue(value) {
|
|
71
|
+
return ContextTokens.findQualifierForValue(value, this.qualifiers);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Converts a {@link ContextToken | context token} to a validated partial context.
|
|
75
|
+
* @param token - the context token to convert
|
|
76
|
+
* @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.
|
|
77
|
+
*/
|
|
78
|
+
contextTokenToPartialContext(token) {
|
|
79
|
+
return ContextTokens.contextTokenToPartialContext(token, this.qualifiers);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Converts a validated partial context to a {@link ContextToken | context token}.
|
|
83
|
+
* @param context - the validated partial context to convert
|
|
84
|
+
* @returns `Success` with the context token if successful, `Failure` with an error message if not.
|
|
85
|
+
*/
|
|
86
|
+
partialContextToContextToken(context) {
|
|
87
|
+
return ContextTokens.partialContextToContextToken(context);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Parses a {@link ContextQualifierToken | context qualifier token} and validates it against the qualifiers
|
|
91
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
92
|
+
* @param token - the token string to parse.
|
|
93
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
94
|
+
* @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,
|
|
95
|
+
* `Failure` with an error message if not.
|
|
96
|
+
*/
|
|
97
|
+
static parseContextQualifierToken(token, qualifiers) {
|
|
98
|
+
return CommonHelpers.parseContextQualifierTokenParts(token).onSuccess((parts) => {
|
|
99
|
+
return ContextTokens.validateContextTokenParts(parts, qualifiers);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Parses a {@link ContextToken | context token} and validates it against the qualifiers
|
|
104
|
+
* present in the supplied {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
105
|
+
* @param token - the token string to parse.
|
|
106
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
107
|
+
* @returns `Success` with an array of {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declarations}
|
|
108
|
+
* if successful, `Failure` with an error message if not
|
|
109
|
+
*/
|
|
110
|
+
static parseContextToken(token, qualifiers) {
|
|
111
|
+
return CommonHelpers.parseContextTokenParts(token).onSuccess((parts) => {
|
|
112
|
+
return mapResults(parts.map((part) => ContextTokens.validateContextTokenParts(part, qualifiers)));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Validates the parts of a context token against the qualifiers present in the supplied
|
|
117
|
+
* {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector}.
|
|
118
|
+
* @param parts - the {@link Helpers.IContextTokenParts | context token parts} to validate.
|
|
119
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} used to
|
|
120
|
+
* validate qualifier names and values.
|
|
121
|
+
* @returns `Success` with a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration} if successful,
|
|
122
|
+
* `Failure` with an error message if not.
|
|
123
|
+
*/
|
|
124
|
+
static validateContextTokenParts(parts, qualifiers) {
|
|
125
|
+
const qualifierLookup = parts.qualifier === undefined
|
|
126
|
+
? ContextTokens.findQualifierForValue(parts.value, qualifiers)
|
|
127
|
+
: qualifiers.getByNameOrToken(parts.qualifier);
|
|
128
|
+
return qualifierLookup.onSuccess((qualifier) => {
|
|
129
|
+
return qualifier.type
|
|
130
|
+
.validateContextValue(parts.value)
|
|
131
|
+
.onSuccess((value) => {
|
|
132
|
+
return succeed({ qualifier, value });
|
|
133
|
+
})
|
|
134
|
+
.withDetail('failure', 'success');
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Given a value and a set of qualifiers, finds a single token-optional qualifier that matches the value.
|
|
139
|
+
* Fails if no qualifiers match, or if more than one qualifier matches.
|
|
140
|
+
* @param value - the value to match.
|
|
141
|
+
* @param qualifiers - the qualifiers to match against.
|
|
142
|
+
* @returns `Success` with the matching qualifier if successful, `Failure` with an error message if not.
|
|
143
|
+
*/
|
|
144
|
+
static findQualifierForValue(value, qualifiers) {
|
|
145
|
+
const matched = [];
|
|
146
|
+
for (const qualifier of qualifiers.values()) {
|
|
147
|
+
if (qualifier.tokenIsOptional && qualifier.validateContextValue(value).isSuccess()) {
|
|
148
|
+
matched.push(qualifier);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (matched.length === 0) {
|
|
152
|
+
return fail(`${value}: does not match any qualifier`);
|
|
153
|
+
}
|
|
154
|
+
if (matched.length > 1) {
|
|
155
|
+
return fail(`${value}: matches multiple qualifiers (${matched.map((q) => q.name).join(', ')})`);
|
|
156
|
+
}
|
|
157
|
+
return succeed(matched[0]);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Converts a {@link ContextToken | context token} to a validated partial context.
|
|
161
|
+
* @param token - the context token to convert
|
|
162
|
+
* @param qualifiers - the {@link Qualifiers.IReadOnlyQualifierCollector | qualifier collector} to use
|
|
163
|
+
* @returns `Success` with the validated partial context if successful, `Failure` with an error message if not.
|
|
164
|
+
*/
|
|
165
|
+
static contextTokenToPartialContext(token, qualifiers) {
|
|
166
|
+
return ContextTokens.parseContextToken(token, qualifiers).onSuccess((qualifierValues) => {
|
|
167
|
+
const context = {};
|
|
168
|
+
for (const { qualifier, value } of qualifierValues) {
|
|
169
|
+
const qualifierName = qualifier.name;
|
|
170
|
+
const contextValue = value;
|
|
171
|
+
// Check for duplicate qualifiers
|
|
172
|
+
if (qualifierName in context) {
|
|
173
|
+
return fail(`${qualifier.name}: duplicate qualifier in context token`);
|
|
174
|
+
}
|
|
175
|
+
context[qualifierName] = contextValue;
|
|
176
|
+
}
|
|
177
|
+
return succeed(context);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Converts a validated partial context to a {@link ContextToken | context token}.
|
|
182
|
+
* @param context - the validated partial context to convert
|
|
183
|
+
* @returns `Success` with the context token if successful, `Failure` with an error message if not.
|
|
184
|
+
*/
|
|
185
|
+
static partialContextToContextToken(context) {
|
|
186
|
+
const tokens = [];
|
|
187
|
+
for (const [qualifierName, contextValue] of Object.entries(context)) {
|
|
188
|
+
// Build token as "qualifier=value"
|
|
189
|
+
tokens.push(`${qualifierName}=${contextValue}`);
|
|
190
|
+
}
|
|
191
|
+
if (tokens.length === 0) {
|
|
192
|
+
return succeed('');
|
|
193
|
+
}
|
|
194
|
+
const tokenString = tokens.join('|');
|
|
195
|
+
// Validate the generated token
|
|
196
|
+
return CommonHelpers.buildContextToken(tokens.map((token) => {
|
|
197
|
+
const [qualifier, value] = token.split('=');
|
|
198
|
+
return { qualifier, value };
|
|
199
|
+
})).onSuccess(() => succeed(tokenString));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=contextToken.js.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import { Converters, Failure, MessageAggregator, succeed, Success } from '@fgv/ts-utils';
|
|
23
|
+
/* eslint-disable @rushstack/typedef-var */
|
|
24
|
+
/**
|
|
25
|
+
* Converter for a {@link Context.IContextQualifierValueDecl | context qualifier value declaration}.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export const contextQualifierValueDecl = Converters.strictObject({
|
|
29
|
+
qualifier: Converters.string,
|
|
30
|
+
value: Converters.string
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Converter for a {@link Context.IContextDecl | context declaration}.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export const contextDecl = Converters.recordOf(Converters.string);
|
|
37
|
+
/**
|
|
38
|
+
* Converter which constructs a {@link Context.IValidatedContextQualifierValueDecl | validated context qualifier value declaration}
|
|
39
|
+
* from a {@link Context.IContextQualifierValueDecl | context qualifier value declaration}, instantiating qualifiers by name
|
|
40
|
+
* from a supplied {@link Context.Convert.IContextDeclConvertContext | conversion context}.
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
export const validatedContextQualifierValueDecl = Converters.generic((from, __self, context) => {
|
|
44
|
+
if (!context) {
|
|
45
|
+
return Failure.with('validatedContextQualifierValueDecl converter requires a context');
|
|
46
|
+
}
|
|
47
|
+
return contextQualifierValueDecl.convert(from).onSuccess((decl) => {
|
|
48
|
+
const { value: qualifier, message } = context.qualifiers.validating.get(decl.qualifier);
|
|
49
|
+
if (message !== undefined) {
|
|
50
|
+
return Failure.with(message);
|
|
51
|
+
}
|
|
52
|
+
return qualifier.validateContextValue(decl.value).onSuccess((value) => {
|
|
53
|
+
return Success.with({
|
|
54
|
+
qualifier,
|
|
55
|
+
value
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* Converter which constructs a {@link Context.IValidatedContextDecl | validated context declaration}
|
|
62
|
+
* from a {@link Context.IContextDecl | context declaration}, instantiating qualifiers by name
|
|
63
|
+
* from a supplied {@link Context.Convert.IContextDeclConvertContext | conversion context}.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export const validatedContextDecl = Converters.generic((from, __self, context) => {
|
|
67
|
+
/* c8 ignore next 3 - functional code path tested but coverage intermittently missed */
|
|
68
|
+
if (!context) {
|
|
69
|
+
return Failure.with('validatedContextDecl converter requires a context');
|
|
70
|
+
}
|
|
71
|
+
return contextDecl.convert(from).onSuccess((decl) => {
|
|
72
|
+
const errors = new MessageAggregator();
|
|
73
|
+
const result = {};
|
|
74
|
+
for (const key in decl) {
|
|
75
|
+
if (key in decl) {
|
|
76
|
+
const { value: qualifier } = context.qualifiers.validating.get(key).aggregateError(errors);
|
|
77
|
+
if (qualifier !== undefined) {
|
|
78
|
+
qualifier
|
|
79
|
+
.validateContextValue(decl[key])
|
|
80
|
+
.onSuccess((value) => {
|
|
81
|
+
result[qualifier.name] = value;
|
|
82
|
+
return succeed(value);
|
|
83
|
+
})
|
|
84
|
+
.aggregateError(errors);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return errors.returnOrReport(Success.with(result));
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=decls.js.map
|