@fgv/ts-res 5.1.0-39 → 5.1.0-40

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.
Files changed (97) hide show
  1. package/dist/packlets/config/common.js +78 -0
  2. package/dist/packlets/config/common.js.map +1 -0
  3. package/dist/packlets/config/configInitFactory.js +258 -0
  4. package/dist/packlets/config/configInitFactory.js.map +1 -0
  5. package/dist/packlets/config/convert.js +56 -0
  6. package/dist/packlets/config/convert.js.map +1 -0
  7. package/dist/packlets/config/index.browser.js +34 -0
  8. package/dist/packlets/config/index.browser.js.map +1 -0
  9. package/dist/packlets/config/index.js +28 -0
  10. package/dist/packlets/config/index.js.map +1 -0
  11. package/dist/packlets/config/json.js +23 -0
  12. package/dist/packlets/config/json.js.map +1 -0
  13. package/dist/packlets/config/predefined/default.js +138 -0
  14. package/dist/packlets/config/predefined/default.js.map +1 -0
  15. package/dist/packlets/config/predefined/extended.js +190 -0
  16. package/dist/packlets/config/predefined/extended.js.map +1 -0
  17. package/dist/packlets/config/predefined/index.js +25 -0
  18. package/dist/packlets/config/predefined/index.js.map +1 -0
  19. package/dist/packlets/config/systemConfiguration.js +147 -0
  20. package/dist/packlets/config/systemConfiguration.js.map +1 -0
  21. package/dist/packlets/qualifier-types/config/convert.js +124 -0
  22. package/dist/packlets/qualifier-types/config/convert.js.map +1 -0
  23. package/dist/packlets/qualifier-types/config/index.js +25 -0
  24. package/dist/packlets/qualifier-types/config/index.js.map +1 -0
  25. package/dist/packlets/qualifier-types/config/json.js +32 -0
  26. package/dist/packlets/qualifier-types/config/json.js.map +1 -0
  27. package/dist/packlets/resource-types/config/convert.js +35 -0
  28. package/dist/packlets/resource-types/config/convert.js.map +1 -0
  29. package/dist/packlets/resource-types/config/index.js +25 -0
  30. package/dist/packlets/resource-types/config/index.js.map +1 -0
  31. package/dist/packlets/resource-types/config/json.js +23 -0
  32. package/dist/packlets/resource-types/config/json.js.map +1 -0
  33. package/lib/packlets/config/common.d.ts +35 -0
  34. package/lib/packlets/config/common.d.ts.map +1 -0
  35. package/lib/packlets/config/common.js +97 -0
  36. package/lib/packlets/config/common.js.map +1 -0
  37. package/lib/packlets/config/configInitFactory.d.ts +217 -0
  38. package/lib/packlets/config/configInitFactory.d.ts.map +1 -0
  39. package/lib/packlets/config/configInitFactory.js +303 -0
  40. package/lib/packlets/config/configInitFactory.js.map +1 -0
  41. package/lib/packlets/config/convert.d.ts +23 -0
  42. package/lib/packlets/config/convert.d.ts.map +1 -0
  43. package/lib/packlets/config/convert.js +93 -0
  44. package/lib/packlets/config/convert.js.map +1 -0
  45. package/lib/packlets/config/index.browser.d.ts +7 -0
  46. package/lib/packlets/config/index.browser.d.ts.map +1 -0
  47. package/lib/packlets/config/index.browser.js +74 -0
  48. package/lib/packlets/config/index.browser.js.map +1 -0
  49. package/lib/packlets/config/index.d.ts +7 -0
  50. package/lib/packlets/config/index.d.ts.map +1 -0
  51. package/lib/packlets/config/index.js +68 -0
  52. package/lib/packlets/config/index.js.map +1 -0
  53. package/lib/packlets/config/json.d.ts +20 -0
  54. package/lib/packlets/config/json.d.ts.map +1 -0
  55. package/lib/packlets/config/json.js +24 -0
  56. package/lib/packlets/config/json.js.map +1 -0
  57. package/lib/packlets/config/predefined/default.d.ts +57 -0
  58. package/lib/packlets/config/predefined/default.d.ts.map +1 -0
  59. package/lib/packlets/config/predefined/default.js +141 -0
  60. package/lib/packlets/config/predefined/default.js.map +1 -0
  61. package/lib/packlets/config/predefined/extended.d.ts +25 -0
  62. package/lib/packlets/config/predefined/extended.d.ts.map +1 -0
  63. package/lib/packlets/config/predefined/extended.js +193 -0
  64. package/lib/packlets/config/predefined/extended.js.map +1 -0
  65. package/lib/packlets/config/predefined/index.d.ts +4 -0
  66. package/lib/packlets/config/predefined/index.d.ts.map +1 -0
  67. package/lib/packlets/config/predefined/index.js +62 -0
  68. package/lib/packlets/config/predefined/index.js.map +1 -0
  69. package/lib/packlets/config/systemConfiguration.d.ts +94 -0
  70. package/lib/packlets/config/systemConfiguration.d.ts.map +1 -0
  71. package/lib/packlets/config/systemConfiguration.js +152 -0
  72. package/lib/packlets/config/systemConfiguration.js.map +1 -0
  73. package/lib/packlets/qualifier-types/config/convert.d.ts +65 -0
  74. package/lib/packlets/qualifier-types/config/convert.d.ts.map +1 -0
  75. package/lib/packlets/qualifier-types/config/convert.js +161 -0
  76. package/lib/packlets/qualifier-types/config/convert.js.map +1 -0
  77. package/lib/packlets/qualifier-types/config/index.d.ts +4 -0
  78. package/lib/packlets/qualifier-types/config/index.d.ts.map +1 -0
  79. package/lib/packlets/qualifier-types/config/index.js +64 -0
  80. package/lib/packlets/qualifier-types/config/index.js.map +1 -0
  81. package/lib/packlets/qualifier-types/config/json.d.ts +91 -0
  82. package/lib/packlets/qualifier-types/config/json.d.ts.map +1 -0
  83. package/lib/packlets/qualifier-types/config/json.js +35 -0
  84. package/lib/packlets/qualifier-types/config/json.js.map +1 -0
  85. package/lib/packlets/resource-types/config/convert.d.ts +8 -0
  86. package/lib/packlets/resource-types/config/convert.d.ts.map +1 -0
  87. package/lib/packlets/resource-types/config/convert.js +38 -0
  88. package/lib/packlets/resource-types/config/convert.js.map +1 -0
  89. package/lib/packlets/resource-types/config/index.d.ts +4 -0
  90. package/lib/packlets/resource-types/config/index.d.ts.map +1 -0
  91. package/lib/packlets/resource-types/config/index.js +64 -0
  92. package/lib/packlets/resource-types/config/index.js.map +1 -0
  93. package/lib/packlets/resource-types/config/json.d.ts +11 -0
  94. package/lib/packlets/resource-types/config/json.d.ts.map +1 -0
  95. package/lib/packlets/resource-types/config/json.js +24 -0
  96. package/lib/packlets/resource-types/config/json.js.map +1 -0
  97. package/package.json +9 -9
@@ -0,0 +1,78 @@
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 { fail } from '@fgv/ts-utils';
23
+ import { SystemConfiguration, updateSystemConfigurationQualifierDefaultValues } from './systemConfiguration';
24
+ import { sanitizeJsonObject } from '@fgv/ts-json-base';
25
+ import { Default, Example } from './predefined';
26
+ /**
27
+ * An array of all well-known predefined system configurations.
28
+ * @public
29
+ */
30
+ export const allPredefinedSystemConfigurations = [
31
+ 'default',
32
+ 'language-priority',
33
+ 'territory-priority',
34
+ 'extended-example'
35
+ ];
36
+ export * from './predefined';
37
+ const predefinedDecls = {
38
+ default: Default.DefaultSystemConfiguration,
39
+ 'language-priority': Default.LanguagePrioritySystemConfiguration,
40
+ 'territory-priority': Default.TerritoryPrioritySystemConfiguration,
41
+ 'extended-example': Example.ExtendedSystemConfiguration
42
+ };
43
+ /**
44
+ * Returns the {@link Config.Model.ISystemConfiguration | system configuration} declaration for the
45
+ * specified predefined system configuration.
46
+ * @param name - The name of the predefined system configuration.
47
+ * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
48
+ * @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}
49
+ * declaration if successful, `Failure` with an error message otherwise.
50
+ * @public
51
+ */
52
+ export function getPredefinedDeclaration(name, initParams) {
53
+ if (name in predefinedDecls) {
54
+ const baseConfig = sanitizeJsonObject(predefinedDecls[name]);
55
+ if (initParams === null || initParams === void 0 ? void 0 : initParams.qualifierDefaultValues) {
56
+ return baseConfig.onSuccess((config) => updateSystemConfigurationQualifierDefaultValues(config, initParams.qualifierDefaultValues));
57
+ }
58
+ return baseConfig;
59
+ }
60
+ /* c8 ignore next 3 - defense in depth */
61
+ return fail(`Unknown predefined system configuration: ${name}`);
62
+ }
63
+ /**
64
+ * Returns the {@link Config.SystemConfiguration | SystemConfiguration} for the specified
65
+ * predefined system configuration.
66
+ * @param name - The name of the predefined system configuration.
67
+ * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.
68
+ * @returns `Success` with the {@link Config.SystemConfiguration | SystemConfiguration}
69
+ * if successful, `Failure` with an error message otherwise.
70
+ * @public
71
+ */
72
+ export function getPredefinedSystemConfiguration(name, initParams) {
73
+ if (name in predefinedDecls) {
74
+ return SystemConfiguration.create(predefinedDecls[name], initParams);
75
+ }
76
+ return fail(`Unknown predefined system configuration: ${name}`);
77
+ }
78
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/packlets/config/common.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAU,IAAI,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EACL,mBAAmB,EAEnB,+CAA+C,EAChD,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAYhD;;;GAGG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAiD;IAC7F,SAAS;IACT,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;CACnB,CAAC;AAEF,cAAc,cAAc,CAAC;AAE7B,MAAM,eAAe,GAAgE;IACnF,OAAO,EAAE,OAAO,CAAC,0BAA0B;IAC3C,mBAAmB,EAAE,OAAO,CAAC,mCAAmC;IAChE,oBAAoB,EAAE,OAAO,CAAC,oCAAoC;IAClE,kBAAkB,EAAE,OAAO,CAAC,2BAA2B;CACxD,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAmC,EACnC,UAA2C;IAE3C,IAAI,IAAI,IAAI,eAAe,EAAE,CAAC;QAC5B,MAAM,UAAU,GAAG,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,sBAAsB,EAAE,CAAC;YACvC,OAAO,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,EAAE,CACrC,+CAA+C,CAAC,MAAM,EAAE,UAAU,CAAC,sBAAuB,CAAC,CAC5F,CAAC;QACJ,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,yCAAyC;IACzC,OAAO,IAAI,CAAC,4CAA4C,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gCAAgC,CAC9C,IAAmC,EACnC,UAA2C;IAE3C,IAAI,IAAI,IAAI,eAAe,EAAE,CAAC;QAC5B,OAAO,mBAAmB,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,IAAI,CAAC,4CAA4C,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, fail } from '@fgv/ts-utils';\nimport { ISystemConfiguration } from './json';\nimport {\n SystemConfiguration,\n ISystemConfigurationInitParams,\n updateSystemConfigurationQualifierDefaultValues\n} from './systemConfiguration';\nimport { sanitizeJsonObject } from '@fgv/ts-json-base';\nimport { Default, Example } from './predefined';\n\n/**\n * A `string` literal type representing a well-known predefined system configuration.\n * @public\n */\nexport type PredefinedSystemConfiguration =\n | 'default'\n | 'language-priority'\n | 'territory-priority'\n | 'extended-example';\n\n/**\n * An array of all well-known predefined system configurations.\n * @public\n */\nexport const allPredefinedSystemConfigurations: ReadonlyArray<PredefinedSystemConfiguration> = [\n 'default',\n 'language-priority',\n 'territory-priority',\n 'extended-example'\n];\n\nexport * from './predefined';\n\nconst predefinedDecls: Record<PredefinedSystemConfiguration, ISystemConfiguration> = {\n default: Default.DefaultSystemConfiguration,\n 'language-priority': Default.LanguagePrioritySystemConfiguration,\n 'territory-priority': Default.TerritoryPrioritySystemConfiguration,\n 'extended-example': Example.ExtendedSystemConfiguration\n};\n\n/**\n * Returns the {@link Config.Model.ISystemConfiguration | system configuration} declaration for the\n * specified predefined system configuration.\n * @param name - The name of the predefined system configuration.\n * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.\n * @returns `Success` with the {@link Config.Model.ISystemConfiguration | system configuration}\n * declaration if successful, `Failure` with an error message otherwise.\n * @public\n */\nexport function getPredefinedDeclaration(\n name: PredefinedSystemConfiguration,\n initParams?: ISystemConfigurationInitParams\n): Result<ISystemConfiguration> {\n if (name in predefinedDecls) {\n const baseConfig = sanitizeJsonObject(predefinedDecls[name]);\n if (initParams?.qualifierDefaultValues) {\n return baseConfig.onSuccess((config) =>\n updateSystemConfigurationQualifierDefaultValues(config, initParams.qualifierDefaultValues!)\n );\n }\n return baseConfig;\n }\n /* c8 ignore next 3 - defense in depth */\n return fail(`Unknown predefined system configuration: ${name}`);\n}\n\n/**\n * Returns the {@link Config.SystemConfiguration | SystemConfiguration} for the specified\n * predefined system configuration.\n * @param name - The name of the predefined system configuration.\n * @param initParams - Optional {@link Config.ISystemConfigurationInitParams | initialization parameters}.\n * @returns `Success` with the {@link Config.SystemConfiguration | SystemConfiguration}\n * if successful, `Failure` with an error message otherwise.\n * @public\n */\nexport function getPredefinedSystemConfiguration(\n name: PredefinedSystemConfiguration,\n initParams?: ISystemConfigurationInitParams\n): Result<SystemConfiguration> {\n if (name in predefinedDecls) {\n return SystemConfiguration.create(predefinedDecls[name], initParams);\n }\n\n return fail(`Unknown predefined system configuration: ${name}`);\n}\n"]}
@@ -0,0 +1,258 @@
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 { fail } from '@fgv/ts-utils';
23
+ import * as QualifierTypes from '../qualifier-types';
24
+ import * as ResourceTypes from '../resource-types';
25
+ /**
26
+ * Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a factory function.
27
+ * @param fn - The factory function to wrap.
28
+ * @returns An `IConfigInitFactory` instance that delegates to the function.
29
+ * @public
30
+ */
31
+ export function createQualifierTypeFactory(fn) {
32
+ return {
33
+ create: fn
34
+ };
35
+ }
36
+ /**
37
+ * Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a resource type factory function.
38
+ * @param fn - The factory function to wrap.
39
+ * @returns An `IConfigInitFactory` instance that delegates to the function.
40
+ * @public
41
+ */
42
+ export function createResourceTypeFactory(fn) {
43
+ return {
44
+ create: fn
45
+ };
46
+ }
47
+ /**
48
+ * A factory that chains multiple factories together.
49
+ * @public
50
+ */
51
+ export class ChainedConfigInitFactory {
52
+ /**
53
+ * Constructor for a chained config init factory.
54
+ * @param factories - The factories to chain.
55
+ */
56
+ constructor(factories) {
57
+ this.factories = factories;
58
+ }
59
+ /**
60
+ * Creates a new instance of a configuration object.
61
+ * @param config - The configuration object to create.
62
+ * @returns A result containing the new instance of the configuration object.
63
+ */
64
+ create(config) {
65
+ for (const factory of this.factories) {
66
+ const result = factory.create(config);
67
+ if (result.isSuccess()) {
68
+ return result;
69
+ }
70
+ }
71
+ return fail('No factory was able to create the configuration object');
72
+ }
73
+ }
74
+ /**
75
+ * A factory that creates a {@link QualifierTypes.SystemQualifierType | SystemQualifierType} from
76
+ * {@link QualifierTypes.Config.IAnyQualifierTypeConfig | any qualifier type configuration}.
77
+ * @returns `Success` with the new {@link QualifierTypes.SystemQualifierType | SystemQualifierType}
78
+ * if successful, `Failure` with an error message otherwise.
79
+ * @public
80
+ */
81
+ export class BuiltInQualifierTypeFactory {
82
+ /** {@inheritDoc Config.IConfigInitFactory.create} */
83
+ create(config) {
84
+ if (QualifierTypes.Config.isSystemQualifierTypeConfig(config)) {
85
+ return QualifierTypes.createQualifierTypeFromSystemConfig(config);
86
+ }
87
+ /* c8 ignore next 2 - functional code tested but coverage intermittently missed */
88
+ return fail(`${config.name}: unknown built-in qualifier type (${config.systemType})`);
89
+ }
90
+ }
91
+ /**
92
+ * A factory that creates {@link QualifierTypes.QualifierType | QualifierType} instances from configuration,
93
+ * supporting both built-in system types and custom external types.
94
+ *
95
+ * This factory allows external consumers to extend the qualifier type system with their own custom types
96
+ * while maintaining support for all built-in types (Language, Territory, Literal).
97
+ *
98
+ * @typeParam T - The custom qualifier type(s) to support. Defaults to {@link QualifierTypes.SystemQualifierType | SystemQualifierType}.
99
+ *
100
+ * @example Creating a factory with custom qualifier types
101
+ * ```typescript
102
+ * // Define a custom qualifier type
103
+ * class CustomQualifierType extends QualifierType {
104
+ * // ... implementation
105
+ * }
106
+ *
107
+ * // Define a discriminated union of all types
108
+ * type AppQualifierType = SystemQualifierType | CustomQualifierType;
109
+ *
110
+ * // Create a factory that handles custom types
111
+ * const customFactory: IConfigInitFactory<IAnyQualifierTypeConfig, CustomQualifierType> = {
112
+ * create(config) {
113
+ * // ... handle custom type creation
114
+ * }
115
+ * };
116
+ *
117
+ * // Create the combined factory
118
+ * const qualifierTypeFactory = new QualifierTypeFactory<AppQualifierType>([customFactory]);
119
+ *
120
+ * // The factory returns T | SystemQualifierType, supporting all types
121
+ * const result = qualifierTypeFactory.create(config); // Result<AppQualifierType | SystemQualifierType>
122
+ * ```
123
+ *
124
+ * @remarks
125
+ * - The factory chains custom factories with the built-in factory
126
+ * - Custom factories are tried first, falling back to built-in types
127
+ * - The return type is a union of custom types (T) and system types
128
+ *
129
+ * @public
130
+ */
131
+ export class QualifierTypeFactory extends ChainedConfigInitFactory {
132
+ /**
133
+ * Constructor for a {@link Config.QualifierTypeFactory | qualifier type factory}.
134
+ * @param factories - Array of factories for custom qualifier types. Can be:
135
+ * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
136
+ * - {@link Config.QualifierTypeFactoryFunction | Factory functions}
137
+ * - A mix of both
138
+ * These are tried in order before falling back to built-in types.
139
+ * @remarks The {@link Config.BuiltInQualifierTypeFactory | built-in factory} is always appended to handle
140
+ * system qualifier types (Language, Territory, Literal).
141
+ */
142
+ constructor(factories) {
143
+ const normalizedFactories = factories.map((f) => typeof f === 'function' ? createQualifierTypeFactory(f) : f);
144
+ super([...normalizedFactories, new BuiltInQualifierTypeFactory()]);
145
+ }
146
+ }
147
+ /**
148
+ * A factory that validates and creates {@link QualifierTypes.QualifierType | QualifierType} instances
149
+ * from weakly-typed configuration objects. This factory accepts configurations with unvalidated
150
+ * string properties and validates them before delegating to the underlying factory chain.
151
+ *
152
+ * This pattern is useful at package boundaries where type identity issues may occur with
153
+ * branded types across different package instances.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * // Accept weakly-typed config from external source
158
+ * const validatingFactory = new ValidatingQualifierTypeFactory([customFactory]);
159
+ *
160
+ * // Config can have plain string types instead of branded types
161
+ * const config = {
162
+ * name: 'my-qualifier', // plain string, not QualifierTypeName
163
+ * systemType: 'custom', // plain string
164
+ * configuration: { ... }
165
+ * };
166
+ *
167
+ * const result = validatingFactory.create(config); // Validates and converts internally
168
+ * ```
169
+ *
170
+ * @public
171
+ */
172
+ export class ValidatingQualifierTypeFactory {
173
+ /**
174
+ * Constructor for a validating qualifier type factory.
175
+ * @param factories - Array of factories for custom qualifier types. Can be:
176
+ * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
177
+ * - {@link Config.QualifierTypeFactoryFunction | Factory functions}
178
+ * - A mix of both
179
+ */
180
+ constructor(factories) {
181
+ this._innerFactory = new QualifierTypeFactory(factories);
182
+ }
183
+ /**
184
+ * Creates a qualifier type from a weakly-typed configuration object.
185
+ * @param config - The configuration object to validate and use for creation.
186
+ * @returns A result containing the new qualifier type if successful.
187
+ */
188
+ create(config) {
189
+ return QualifierTypes.Config.Convert.anyQualifierTypeConfig
190
+ .convert(config)
191
+ .onSuccess((validatedConfig) => {
192
+ return this._innerFactory.create(validatedConfig);
193
+ });
194
+ }
195
+ }
196
+ /**
197
+ * A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}.
198
+ * @public
199
+ */
200
+ export class BuiltInResourceTypeFactory {
201
+ /** {@inheritDoc Config.IConfigInitFactory.create} */
202
+ create(config) {
203
+ return ResourceTypes.createResourceTypeFromConfig(config);
204
+ }
205
+ }
206
+ /**
207
+ * A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}
208
+ * by chaining a supplied factory with a {@link Config.BuiltInResourceTypeFactory | built-in factory} that handles built-in resource types.
209
+ * @public
210
+ */
211
+ export class ResourceTypeFactory extends ChainedConfigInitFactory {
212
+ /**
213
+ * Constructor for a resource type factory.
214
+ * @param factories - Array of factories for resource types. Can be:
215
+ * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
216
+ * - {@link Config.ResourceTypeFactoryFunction | Factory functions}
217
+ * - A mix of both
218
+ * @remarks The {@link Config.BuiltInResourceTypeFactory | built-in factory} is always added to the end of the chain.
219
+ */
220
+ constructor(factories) {
221
+ factories = factories !== null && factories !== void 0 ? factories : [];
222
+ const normalizedFactories = factories.map((f) => typeof f === 'function' ? createResourceTypeFactory(f) : f);
223
+ super([...normalizedFactories, new BuiltInResourceTypeFactory()]);
224
+ }
225
+ }
226
+ /**
227
+ * A factory that validates and creates {@link ResourceTypes.ResourceType | ResourceType} instances
228
+ * from weakly-typed configuration objects. This factory accepts configurations with unvalidated
229
+ * string properties and validates them before delegating to the underlying factory chain.
230
+ *
231
+ * This pattern is useful at package boundaries where type identity issues may occur with
232
+ * branded types across different package instances.
233
+ *
234
+ * @public
235
+ */
236
+ export class ValidatingResourceTypeFactory {
237
+ /**
238
+ * Constructor for a validating resource type factory.
239
+ * @param factories - Array of factories for resource types. Can be:
240
+ * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances
241
+ * - {@link Config.ResourceTypeFactoryFunction | Factory functions}
242
+ * - A mix of both
243
+ */
244
+ constructor(factories) {
245
+ this._innerFactory = new ResourceTypeFactory(factories);
246
+ }
247
+ /**
248
+ * Creates a resource type from a weakly-typed configuration object.
249
+ * @param config - The configuration object to validate and use for creation.
250
+ * @returns A result containing the new resource type if successful.
251
+ */
252
+ create(config) {
253
+ return ResourceTypes.Config.Convert.resourceTypeConfig.convert(config).onSuccess((validatedConfig) => {
254
+ return this._innerFactory.create(validatedConfig);
255
+ });
256
+ }
257
+ }
258
+ //# sourceMappingURL=configInitFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configInitFactory.js","sourceRoot":"","sources":["../../../src/packlets/config/configInitFactory.ts"],"names":[],"mappings":"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","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Result, fail } from '@fgv/ts-utils';\nimport { QualifierType, SystemQualifierType } from '../qualifier-types';\nimport * as QualifierTypes from '../qualifier-types';\nimport * as ResourceTypes from '../resource-types';\nimport { ResourceType } from '../resource-types';\n\n/**\n * Function signature for creating a qualifier type from configuration.\n * @public\n */\nexport type QualifierTypeFactoryFunction<T extends QualifierType = QualifierType> = (\n config: QualifierTypes.Config.IAnyQualifierTypeConfig\n) => Result<T>;\n\n/**\n * Function signature for creating a resource type from configuration.\n * @public\n */\nexport type ResourceTypeFactoryFunction = (\n config: ResourceTypes.Config.IResourceTypeConfig\n) => Result<ResourceType>;\n\n/**\n * Interface for a factory that creates a new instance of a configuration object.\n * @public\n */\nexport interface IConfigInitFactory<TConfig, T> {\n /**\n * Creates a new instance of a configuration object.\n * @param config - The configuration object to create.\n * @returns A result containing the new instance of the configuration object.\n */\n create(config: TConfig): Result<T>;\n}\n\n/**\n * Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a factory function.\n * @param fn - The factory function to wrap.\n * @returns An `IConfigInitFactory` instance that delegates to the function.\n * @public\n */\nexport function createQualifierTypeFactory<T extends QualifierType = QualifierType>(\n fn: QualifierTypeFactoryFunction<T>\n): IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> {\n return {\n create: fn\n };\n}\n\n/**\n * Creates a {@link Config.IConfigInitFactory | IConfigInitFactory} from a resource type factory function.\n * @param fn - The factory function to wrap.\n * @returns An `IConfigInitFactory` instance that delegates to the function.\n * @public\n */\nexport function createResourceTypeFactory(\n fn: ResourceTypeFactoryFunction\n): IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> {\n return {\n create: fn\n };\n}\n\n/**\n * A factory that chains multiple factories together.\n * @public\n */\nexport class ChainedConfigInitFactory<TConfig, T> implements IConfigInitFactory<TConfig, T> {\n public readonly factories: IConfigInitFactory<TConfig, T>[];\n\n /**\n * Constructor for a chained config init factory.\n * @param factories - The factories to chain.\n */\n public constructor(factories: IConfigInitFactory<TConfig, T>[]) {\n this.factories = factories;\n }\n\n /**\n * Creates a new instance of a configuration object.\n * @param config - The configuration object to create.\n * @returns A result containing the new instance of the configuration object.\n */\n public create(config: TConfig): Result<T> {\n for (const factory of this.factories) {\n const result = factory.create(config);\n if (result.isSuccess()) {\n return result;\n }\n }\n return fail('No factory was able to create the configuration object');\n }\n}\n\n/**\n * A factory that creates a {@link QualifierTypes.SystemQualifierType | SystemQualifierType} from\n * {@link QualifierTypes.Config.IAnyQualifierTypeConfig | any qualifier type configuration}.\n * @returns `Success` with the new {@link QualifierTypes.SystemQualifierType | SystemQualifierType}\n * if successful, `Failure` with an error message otherwise.\n * @public\n */\nexport class BuiltInQualifierTypeFactory\n implements IConfigInitFactory<QualifierTypes.Config.ISystemQualifierTypeConfig, SystemQualifierType>\n{\n /** {@inheritDoc Config.IConfigInitFactory.create} */\n public create(config: QualifierTypes.Config.IAnyQualifierTypeConfig): Result<SystemQualifierType> {\n if (QualifierTypes.Config.isSystemQualifierTypeConfig(config)) {\n return QualifierTypes.createQualifierTypeFromSystemConfig(config);\n }\n /* c8 ignore next 2 - functional code tested but coverage intermittently missed */\n return fail(`${config.name}: unknown built-in qualifier type (${config.systemType})`);\n }\n}\n\n/**\n * A factory that creates {@link QualifierTypes.QualifierType | QualifierType} instances from configuration,\n * supporting both built-in system types and custom external types.\n *\n * This factory allows external consumers to extend the qualifier type system with their own custom types\n * while maintaining support for all built-in types (Language, Territory, Literal).\n *\n * @typeParam T - The custom qualifier type(s) to support. Defaults to {@link QualifierTypes.SystemQualifierType | SystemQualifierType}.\n *\n * @example Creating a factory with custom qualifier types\n * ```typescript\n * // Define a custom qualifier type\n * class CustomQualifierType extends QualifierType {\n * // ... implementation\n * }\n *\n * // Define a discriminated union of all types\n * type AppQualifierType = SystemQualifierType | CustomQualifierType;\n *\n * // Create a factory that handles custom types\n * const customFactory: IConfigInitFactory<IAnyQualifierTypeConfig, CustomQualifierType> = {\n * create(config) {\n * // ... handle custom type creation\n * }\n * };\n *\n * // Create the combined factory\n * const qualifierTypeFactory = new QualifierTypeFactory<AppQualifierType>([customFactory]);\n *\n * // The factory returns T | SystemQualifierType, supporting all types\n * const result = qualifierTypeFactory.create(config); // Result<AppQualifierType | SystemQualifierType>\n * ```\n *\n * @remarks\n * - The factory chains custom factories with the built-in factory\n * - Custom factories are tried first, falling back to built-in types\n * - The return type is a union of custom types (T) and system types\n *\n * @public\n */\nexport class QualifierTypeFactory<\n T extends QualifierType = SystemQualifierType\n> extends ChainedConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T | SystemQualifierType> {\n /**\n * Constructor for a {@link Config.QualifierTypeFactory | qualifier type factory}.\n * @param factories - Array of factories for custom qualifier types. Can be:\n * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances\n * - {@link Config.QualifierTypeFactoryFunction | Factory functions}\n * - A mix of both\n * These are tried in order before falling back to built-in types.\n * @remarks The {@link Config.BuiltInQualifierTypeFactory | built-in factory} is always appended to handle\n * system qualifier types (Language, Territory, Literal).\n */\n public constructor(\n factories: Array<\n IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> | QualifierTypeFactoryFunction<T>\n >\n ) {\n const normalizedFactories = factories.map((f) =>\n typeof f === 'function' ? createQualifierTypeFactory(f) : f\n );\n super([...normalizedFactories, new BuiltInQualifierTypeFactory()]);\n }\n}\n\n/**\n * A factory that validates and creates {@link QualifierTypes.QualifierType | QualifierType} instances\n * from weakly-typed configuration objects. This factory accepts configurations with unvalidated\n * string properties and validates them before delegating to the underlying factory chain.\n *\n * This pattern is useful at package boundaries where type identity issues may occur with\n * branded types across different package instances.\n *\n * @example\n * ```typescript\n * // Accept weakly-typed config from external source\n * const validatingFactory = new ValidatingQualifierTypeFactory([customFactory]);\n *\n * // Config can have plain string types instead of branded types\n * const config = {\n * name: 'my-qualifier', // plain string, not QualifierTypeName\n * systemType: 'custom', // plain string\n * configuration: { ... }\n * };\n *\n * const result = validatingFactory.create(config); // Validates and converts internally\n * ```\n *\n * @public\n */\nexport class ValidatingQualifierTypeFactory<T extends QualifierType = SystemQualifierType>\n implements IConfigInitFactory<unknown, T | SystemQualifierType>\n{\n private readonly _innerFactory: QualifierTypeFactory<T>;\n\n /**\n * Constructor for a validating qualifier type factory.\n * @param factories - Array of factories for custom qualifier types. Can be:\n * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances\n * - {@link Config.QualifierTypeFactoryFunction | Factory functions}\n * - A mix of both\n */\n public constructor(\n factories: Array<\n IConfigInitFactory<QualifierTypes.Config.IAnyQualifierTypeConfig, T> | QualifierTypeFactoryFunction<T>\n >\n ) {\n this._innerFactory = new QualifierTypeFactory(factories);\n }\n\n /**\n * Creates a qualifier type from a weakly-typed configuration object.\n * @param config - The configuration object to validate and use for creation.\n * @returns A result containing the new qualifier type if successful.\n */\n public create(config: unknown): Result<T | SystemQualifierType> {\n return QualifierTypes.Config.Convert.anyQualifierTypeConfig\n .convert(config)\n .onSuccess((validatedConfig) => {\n return this._innerFactory.create(validatedConfig);\n });\n }\n}\n\n/**\n * A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}.\n * @public\n */\nexport class BuiltInResourceTypeFactory\n implements IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType>\n{\n /** {@inheritDoc Config.IConfigInitFactory.create} */\n public create(config: ResourceTypes.Config.IResourceTypeConfig): Result<ResourceType> {\n return ResourceTypes.createResourceTypeFromConfig(config);\n }\n}\n\n/**\n * A factory that creates a {@link ResourceTypes.ResourceType | ResourceType} from a {@link ResourceTypes.Config.IResourceTypeConfig | resource type configuration}\n * by chaining a supplied factory with a {@link Config.BuiltInResourceTypeFactory | built-in factory} that handles built-in resource types.\n * @public\n */\nexport class ResourceTypeFactory extends ChainedConfigInitFactory<\n ResourceTypes.Config.IResourceTypeConfig,\n ResourceType\n> {\n /**\n * Constructor for a resource type factory.\n * @param factories - Array of factories for resource types. Can be:\n * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances\n * - {@link Config.ResourceTypeFactoryFunction | Factory functions}\n * - A mix of both\n * @remarks The {@link Config.BuiltInResourceTypeFactory | built-in factory} is always added to the end of the chain.\n */\n public constructor(\n factories: Array<\n IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> | ResourceTypeFactoryFunction\n >\n ) {\n factories = factories ?? [];\n const normalizedFactories = factories.map((f) =>\n typeof f === 'function' ? createResourceTypeFactory(f) : f\n );\n super([...normalizedFactories, new BuiltInResourceTypeFactory()]);\n }\n}\n\n/**\n * A factory that validates and creates {@link ResourceTypes.ResourceType | ResourceType} instances\n * from weakly-typed configuration objects. This factory accepts configurations with unvalidated\n * string properties and validates them before delegating to the underlying factory chain.\n *\n * This pattern is useful at package boundaries where type identity issues may occur with\n * branded types across different package instances.\n *\n * @public\n */\nexport class ValidatingResourceTypeFactory implements IConfigInitFactory<unknown, ResourceType> {\n private readonly _innerFactory: ResourceTypeFactory;\n\n /**\n * Constructor for a validating resource type factory.\n * @param factories - Array of factories for resource types. Can be:\n * - {@link Config.IConfigInitFactory | IConfigInitFactory} instances\n * - {@link Config.ResourceTypeFactoryFunction | Factory functions}\n * - A mix of both\n */\n public constructor(\n factories: Array<\n IConfigInitFactory<ResourceTypes.Config.IResourceTypeConfig, ResourceType> | ResourceTypeFactoryFunction\n >\n ) {\n this._innerFactory = new ResourceTypeFactory(factories);\n }\n\n /**\n * Creates a resource type from a weakly-typed configuration object.\n * @param config - The configuration object to validate and use for creation.\n * @returns A result containing the new resource type if successful.\n */\n public create(config: unknown): Result<ResourceType> {\n return ResourceTypes.Config.Convert.resourceTypeConfig.convert(config).onSuccess((validatedConfig) => {\n return this._innerFactory.create(validatedConfig);\n });\n }\n}\n"]}
@@ -0,0 +1,56 @@
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
+ /* eslint-disable @rushstack/typedef-var */
23
+ import { Converters } from '@fgv/ts-utils';
24
+ import * as QualifierTypes from '../qualifier-types';
25
+ import * as Qualifiers from '../qualifiers';
26
+ import * as ResourceTypes from '../resource-types';
27
+ import { allPredefinedSystemConfigurations } from './common';
28
+ /**
29
+ * A `Converter` for {@link Config.Model.ISystemConfiguration | ISystemConfiguration} objects.
30
+ * @returns A `Converter` for {@link Config.Model.ISystemConfiguration | ISystemConfiguration} objects.
31
+ * @public
32
+ */
33
+ export const systemConfiguration = Converters.strictObject({
34
+ name: Converters.optionalString,
35
+ description: Converters.optionalString,
36
+ qualifierTypes: Converters.arrayOf(QualifierTypes.Config.Convert.anyQualifierTypeConfig),
37
+ qualifiers: Converters.arrayOf(Qualifiers.Convert.qualifierDecl),
38
+ resourceTypes: Converters.arrayOf(ResourceTypes.Config.Convert.resourceTypeConfig)
39
+ });
40
+ /**
41
+ * A `Converter` for {@link Config.PredefinedSystemConfiguration | PredefinedSystemConfiguration} values.
42
+ * @returns A `Converter` for {@link Config.PredefinedSystemConfiguration | PredefinedSystemConfiguration} values.
43
+ * @public
44
+ */
45
+ export const predefinedSystemConfiguration = Converters.enumeratedValue(allPredefinedSystemConfigurations);
46
+ /**
47
+ * Validate a {@link Config.Model.ISystemConfiguration | ISystemConfiguration} object.
48
+ * @param config - The system configuration to validate
49
+ * @returns `Success` with the validated system configuration if successful,
50
+ * or `Failure` with an error message if validation fails.
51
+ * @public
52
+ */
53
+ export function validateSystemConfiguration(config) {
54
+ return systemConfiguration.convert(config);
55
+ }
56
+ //# sourceMappingURL=convert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/packlets/config/convert.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,2CAA2C;AAE3C,OAAO,EAAE,UAAU,EAAU,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,aAAa,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iCAAiC,EAAE,MAAM,UAAU,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC,YAAY,CAAuB;IAC/E,IAAI,EAAE,UAAU,CAAC,cAAc;IAC/B,WAAW,EAAE,UAAU,CAAC,cAAc;IACtC,cAAc,EAAE,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC;IACxF,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC;IAChE,aAAa,EAAE,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC;CACnF,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,UAAU,CAAC,eAAe,CAAC,iCAAiC,CAAC,CAAC;AAE3G;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAAC,MAAe;IACzD,OAAO,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/* eslint-disable @rushstack/typedef-var */\n\nimport { Converters, Result } from '@fgv/ts-utils';\nimport { ISystemConfiguration } from './json';\nimport * as QualifierTypes from '../qualifier-types';\nimport * as Qualifiers from '../qualifiers';\nimport * as ResourceTypes from '../resource-types';\nimport { allPredefinedSystemConfigurations } from './common';\n\n/**\n * A `Converter` for {@link Config.Model.ISystemConfiguration | ISystemConfiguration} objects.\n * @returns A `Converter` for {@link Config.Model.ISystemConfiguration | ISystemConfiguration} objects.\n * @public\n */\nexport const systemConfiguration = Converters.strictObject<ISystemConfiguration>({\n name: Converters.optionalString,\n description: Converters.optionalString,\n qualifierTypes: Converters.arrayOf(QualifierTypes.Config.Convert.anyQualifierTypeConfig),\n qualifiers: Converters.arrayOf(Qualifiers.Convert.qualifierDecl),\n resourceTypes: Converters.arrayOf(ResourceTypes.Config.Convert.resourceTypeConfig)\n});\n\n/**\n * A `Converter` for {@link Config.PredefinedSystemConfiguration | PredefinedSystemConfiguration} values.\n * @returns A `Converter` for {@link Config.PredefinedSystemConfiguration | PredefinedSystemConfiguration} values.\n * @public\n */\nexport const predefinedSystemConfiguration = Converters.enumeratedValue(allPredefinedSystemConfigurations);\n\n/**\n * Validate a {@link Config.Model.ISystemConfiguration | ISystemConfiguration} object.\n * @param config - The system configuration to validate\n * @returns `Success` with the validated system configuration if successful,\n * or `Failure` with an error message if validation fails.\n * @public\n */\nexport function validateSystemConfiguration(config: unknown): Result<ISystemConfiguration> {\n return systemConfiguration.convert(config);\n}\n"]}
@@ -0,0 +1,34 @@
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
+ // Browser-safe config exports - excludes Node.js filesystem dependencies
23
+ import * as Model from './json';
24
+ import * as Convert from './convert';
25
+ // Export all modules
26
+ export * from './configInitFactory';
27
+ export * from './common';
28
+ // Export SystemConfiguration class but not as wildcard to avoid pulling in loadFromFile
29
+ export { SystemConfiguration } from './systemConfiguration';
30
+ // Export namespaces
31
+ export { Model, Convert };
32
+ // Excluded from browser:
33
+ // - SystemConfiguration.loadFromFile() method (requires Node.js fs via JsonFile)
34
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/packlets/config/index.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,yEAAyE;AAEzE,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,qBAAqB;AACrB,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AAEzB,wFAAwF;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,oBAAoB;AACpB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAE1B,yBAAyB;AACzB,iFAAiF","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n// Browser-safe config exports - excludes Node.js filesystem dependencies\n\nimport * as Model from './json';\nimport * as Convert from './convert';\n\n// Export all modules\nexport * from './configInitFactory';\nexport * from './common';\n\n// Export SystemConfiguration class but not as wildcard to avoid pulling in loadFromFile\nexport { SystemConfiguration } from './systemConfiguration';\n\n// Export namespaces\nexport { Model, Convert };\n\n// Excluded from browser:\n// - SystemConfiguration.loadFromFile() method (requires Node.js fs via JsonFile)\n"]}
@@ -0,0 +1,28 @@
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 Model from './json';
23
+ import * as Convert from './convert';
24
+ export * from './configInitFactory';
25
+ export * from './systemConfiguration';
26
+ export * from './common';
27
+ export { Model, Convert };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,KAAK,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AAEzB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as Model from './json';\nimport * as Convert from './convert';\n\nexport * from './configInitFactory';\nexport * from './systemConfiguration';\nexport * from './common';\n\nexport { Model, Convert };\n"]}
@@ -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=json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/packlets/config/json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG","sourcesContent":["/*\n * Copyright (c) 2025 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport * as QualifierTypes from '../qualifier-types';\nimport * as Qualifiers from '../qualifiers';\nimport * as ResourceTypes from '../resource-types';\n\n/**\n * System configuration for both runtime or build.\n * @public\n */\nexport interface ISystemConfiguration {\n /** Optional human-readable name for the configuration. */\n\n name?: string;\n /** Optional description explaining the purpose and use case of the configuration. */\n description?: string;\n /** Qualifier type configurations that define the available qualifier types in the system. */\n qualifierTypes: QualifierTypes.Config.IAnyQualifierTypeConfig[];\n /** Qualifier declarations that define the available qualifiers in the system. */\n qualifiers: Qualifiers.IQualifierDecl[];\n /** Resource type configurations that define the available resource types in the system. */\n resourceTypes: ResourceTypes.Config.IResourceTypeConfig[];\n}\n"]}