@fgv/ts-res 5.0.0-19 → 5.0.0-20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ts-res.d.ts CHANGED
@@ -1738,7 +1738,7 @@ declare const containerContextDecl: Converter<Normalized.IContainerContextDecl>;
1738
1738
 
1739
1739
  declare namespace Context {
1740
1740
  export {
1741
- Convert_7 as Convert,
1741
+ Convert_8 as Convert,
1742
1742
  IContextMatchOptions,
1743
1743
  IContextQualifierValueDecl,
1744
1744
  IContextDecl,
@@ -2168,16 +2168,6 @@ declare namespace Convert_6 {
2168
2168
  }
2169
2169
 
2170
2170
  declare namespace Convert_7 {
2171
- export {
2172
- contextQualifierValueDecl,
2173
- contextDecl,
2174
- IContextDeclConvertContext,
2175
- validatedContextQualifierValueDecl,
2176
- validatedContextDecl
2177
- }
2178
- }
2179
-
2180
- declare namespace Convert_8 {
2181
2171
  export {
2182
2172
  looseConditionDecl,
2183
2173
  childConditionDecl,
@@ -2195,6 +2185,16 @@ declare namespace Convert_8 {
2195
2185
  }
2196
2186
  }
2197
2187
 
2188
+ declare namespace Convert_8 {
2189
+ export {
2190
+ contextQualifierValueDecl,
2191
+ contextDecl,
2192
+ IContextDeclConvertContext,
2193
+ validatedContextQualifierValueDecl,
2194
+ validatedContextDecl
2195
+ }
2196
+ }
2197
+
2198
2198
  declare namespace Convert_9 {
2199
2199
  export {
2200
2200
  validateSystemConfiguration,
@@ -5158,6 +5158,14 @@ declare interface IResourceType<T = unknown> extends ICollectible<ResourceTypeNa
5158
5158
  * Sets the index for this resource type. Once set, the index cannot be changed.
5159
5159
  */
5160
5160
  setIndex(index: number): Result<ResourceTypeIndex>;
5161
+ /**
5162
+ * Creates a template for a new resource of this type.
5163
+ * The template provides a default structure for creating new resource instances.
5164
+ * @param resourceId - The id for the new resource
5165
+ * @returns A loose resource declaration with default values for this resource type
5166
+ * @public
5167
+ */
5168
+ createTemplate(resourceId: ResourceId): ResourceJson.Json.ILooseResourceDecl;
5161
5169
  }
5162
5170
 
5163
5171
  /**
@@ -5915,6 +5923,11 @@ declare class JsonResourceType extends ResourceType<JsonObject> {
5915
5923
  * {@inheritdoc ResourceTypes.ResourceType.(validate:3)}
5916
5924
  */
5917
5925
  validate(json: JsonObject, completeness: 'partial'): Result<JsonObject>;
5926
+ /**
5927
+ * Gets the default template value for a JSON resource type.
5928
+ * @returns An empty object as the default JSON value
5929
+ */
5930
+ protected getDefaultTemplateValue(): JsonObject;
5918
5931
  }
5919
5932
 
5920
5933
  /**
@@ -7752,7 +7765,7 @@ declare const resourceIndex: Converter<ResourceIndex, unknown>;
7752
7765
  declare namespace ResourceJson {
7753
7766
  export {
7754
7767
  Compiled,
7755
- Convert_8 as Convert,
7768
+ Convert_7 as Convert,
7756
7769
  Helpers_2 as Helpers,
7757
7770
  Json,
7758
7771
  Normalized,
@@ -8417,7 +8430,7 @@ declare const resourceTreeChildNodeDecl: Converter<Normalized.IResourceTreeChild
8417
8430
  * strongly-typed internal tree operations, ensuring type safety and consistent
8418
8431
  * error handling throughout the resource tree navigation.
8419
8432
  *
8420
- * @internal
8433
+ * @public
8421
8434
  */
8422
8435
  declare class ResourceTreeChildrenValidator<T> implements IReadOnlyResourceTreeChildren<T, string, string> {
8423
8436
  private readonly _inner;
@@ -8472,17 +8485,17 @@ declare class ResourceTreeChildrenValidator<T> implements IReadOnlyResourceTreeC
8472
8485
  */
8473
8486
  forEach(cb: (value: unknown, key: string, map: IReadOnlyResultMap<string, unknown>, thisArg?: unknown) => void, arg?: unknown): void;
8474
8487
  /**
8475
- * Gets a child node by its ResourceName key with detailed error information.
8476
- * @param key - The ResourceName key to look up
8488
+ * Gets a child node by its string key with detailed error information.
8489
+ * @param key - The string key to look up
8477
8490
  * @returns DetailedResult containing the node if found, or failure with details
8478
8491
  */
8479
- get(key: ResourceName): DetailedResult<IReadOnlyResourceTreeNode<T>, Collections.ResultMapResultDetail>;
8492
+ get(key: string): DetailedResult<IReadOnlyResourceTreeNode<T>, Collections.ResultMapResultDetail>;
8480
8493
  /**
8481
- * Checks if a child node exists at the given ResourceName key.
8482
- * @param key - The ResourceName key to check
8494
+ * Checks if a child node exists at the given string key.
8495
+ * @param key - The string key to check
8483
8496
  * @returns True if a child node exists at the key, false otherwise
8484
8497
  */
8485
- has(key: ResourceName): boolean;
8498
+ has(key: string): boolean;
8486
8499
  /**
8487
8500
  * Returns an iterator of ResourceName keys for all child nodes.
8488
8501
  * @returns Map iterator for all child node keys
@@ -8578,6 +8591,21 @@ export declare abstract class ResourceType<T = unknown> implements IResourceType
8578
8591
  * Sets the index for this resource type. Once set, the index cannot be changed.
8579
8592
  */
8580
8593
  setIndex(index: number): Result<ResourceTypeIndex>;
8594
+ /**
8595
+ * Creates a template for a new resource of this type.
8596
+ * Default implementation provides a basic template.
8597
+ * Subclasses can override to provide type-specific templates.
8598
+ * @param resourceId - The id for the new resource
8599
+ * @returns A loose resource declaration with default values for this resource type
8600
+ * @public
8601
+ */
8602
+ createTemplate(resourceId: ResourceId): ResourceJson.Json.ILooseResourceDecl;
8603
+ /**
8604
+ * Gets the default template value for this resource type.
8605
+ * Subclasses should override this to provide type-specific default values.
8606
+ * @returns The default JSON value for a new resource of this type
8607
+ */
8608
+ protected getDefaultTemplateValue(): JsonObject;
8581
8609
  }
8582
8610
 
8583
8611
  /**
@@ -53,5 +53,10 @@ export declare class JsonResourceType extends ResourceType<JsonObject> {
53
53
  * {@inheritdoc ResourceTypes.ResourceType.(validate:3)}
54
54
  */
55
55
  validate(json: JsonObject, completeness: 'partial'): Result<JsonObject>;
56
+ /**
57
+ * Gets the default template value for a JSON resource type.
58
+ * @returns An empty object as the default JSON value
59
+ */
60
+ protected getDefaultTemplateValue(): JsonObject;
56
61
  }
57
62
  //# sourceMappingURL=jsonResourceType.d.ts.map
@@ -61,6 +61,13 @@ class JsonResourceType extends resourceType_1.ResourceType {
61
61
  validate(json, __completeness) {
62
62
  return ts_json_base_1.Converters.jsonObject.convert(json);
63
63
  }
64
+ /**
65
+ * Gets the default template value for a JSON resource type.
66
+ * @returns An empty object as the default JSON value
67
+ */
68
+ getDefaultTemplateValue() {
69
+ return {};
70
+ }
64
71
  }
65
72
  exports.JsonResourceType = JsonResourceType;
66
73
  //# sourceMappingURL=jsonResourceType.js.map
@@ -1,6 +1,7 @@
1
- import { JsonValue } from '@fgv/ts-json-base';
1
+ import { JsonValue, JsonObject } from '@fgv/ts-json-base';
2
2
  import { ICollectible, Result } from '@fgv/ts-utils';
3
3
  import { CandidateCompleteness, ResourceTypeIndex, ResourceTypeName, ResourceValueMergeMethod, ResourceId } from '../common';
4
+ import * as ResourceJson from '../resource-json';
4
5
  /**
5
6
  * Parameters used to validate a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}.
6
7
  * @public
@@ -82,6 +83,14 @@ export interface IResourceType<T = unknown> extends ICollectible<ResourceTypeNam
82
83
  * Sets the index for this resource type. Once set, the index cannot be changed.
83
84
  */
84
85
  setIndex(index: number): Result<ResourceTypeIndex>;
86
+ /**
87
+ * Creates a template for a new resource of this type.
88
+ * The template provides a default structure for creating new resource instances.
89
+ * @param resourceId - The id for the new resource
90
+ * @returns A loose resource declaration with default values for this resource type
91
+ * @public
92
+ */
93
+ createTemplate(resourceId: ResourceId): ResourceJson.Json.ILooseResourceDecl;
85
94
  }
86
95
  /**
87
96
  * Abstract base class for resource types which are responsible for
@@ -149,5 +158,20 @@ export declare abstract class ResourceType<T = unknown> implements IResourceType
149
158
  * Sets the index for this resource type. Once set, the index cannot be changed.
150
159
  */
151
160
  setIndex(index: number): Result<ResourceTypeIndex>;
161
+ /**
162
+ * Creates a template for a new resource of this type.
163
+ * Default implementation provides a basic template.
164
+ * Subclasses can override to provide type-specific templates.
165
+ * @param resourceId - The id for the new resource
166
+ * @returns A loose resource declaration with default values for this resource type
167
+ * @public
168
+ */
169
+ createTemplate(resourceId: ResourceId): ResourceJson.Json.ILooseResourceDecl;
170
+ /**
171
+ * Gets the default template value for this resource type.
172
+ * Subclasses should override this to provide type-specific default values.
173
+ * @returns The default JSON value for a new resource of this type
174
+ */
175
+ protected getDefaultTemplateValue(): JsonObject;
152
176
  }
153
177
  //# sourceMappingURL=resourceType.d.ts.map
@@ -57,6 +57,38 @@ class ResourceType {
57
57
  setIndex(index) {
58
58
  return this._collectible.setIndex(index);
59
59
  }
60
+ /**
61
+ * Creates a template for a new resource of this type.
62
+ * Default implementation provides a basic template.
63
+ * Subclasses can override to provide type-specific templates.
64
+ * @param resourceId - The id for the new resource
65
+ * @returns A loose resource declaration with default values for this resource type
66
+ * @public
67
+ */
68
+ createTemplate(resourceId) {
69
+ return {
70
+ id: resourceId,
71
+ resourceTypeName: this.key,
72
+ candidates: [
73
+ {
74
+ json: this.getDefaultTemplateValue(),
75
+ conditions: undefined,
76
+ isPartial: false,
77
+ mergeMethod: 'replace'
78
+ }
79
+ ]
80
+ };
81
+ }
82
+ /**
83
+ * Gets the default template value for this resource type.
84
+ * Subclasses should override this to provide type-specific default values.
85
+ * @returns The default JSON value for a new resource of this type
86
+ */
87
+ getDefaultTemplateValue() {
88
+ // Default implementation returns an empty object
89
+ // Subclasses should override for type-specific defaults
90
+ return {};
91
+ }
60
92
  }
61
93
  exports.ResourceType = ResourceType;
62
94
  //# sourceMappingURL=resourceType.js.map
@@ -14,7 +14,7 @@ import { IReadOnlyResourceTreeBranch, IReadOnlyResourceTreeChildren, IReadOnlyRe
14
14
  * strongly-typed internal tree operations, ensuring type safety and consistent
15
15
  * error handling throughout the resource tree navigation.
16
16
  *
17
- * @internal
17
+ * @public
18
18
  */
19
19
  export declare class ResourceTreeChildrenValidator<T> implements IReadOnlyResourceTreeChildren<T, string, string> {
20
20
  private readonly _inner;
@@ -69,17 +69,17 @@ export declare class ResourceTreeChildrenValidator<T> implements IReadOnlyResour
69
69
  */
70
70
  forEach(cb: (value: unknown, key: string, map: IReadOnlyResultMap<string, unknown>, thisArg?: unknown) => void, arg?: unknown): void;
71
71
  /**
72
- * Gets a child node by its ResourceName key with detailed error information.
73
- * @param key - The ResourceName key to look up
72
+ * Gets a child node by its string key with detailed error information.
73
+ * @param key - The string key to look up
74
74
  * @returns DetailedResult containing the node if found, or failure with details
75
75
  */
76
- get(key: ResourceName): DetailedResult<IReadOnlyResourceTreeNode<T>, Collections.ResultMapResultDetail>;
76
+ get(key: string): DetailedResult<IReadOnlyResourceTreeNode<T>, Collections.ResultMapResultDetail>;
77
77
  /**
78
- * Checks if a child node exists at the given ResourceName key.
79
- * @param key - The ResourceName key to check
78
+ * Checks if a child node exists at the given string key.
79
+ * @param key - The string key to check
80
80
  * @returns True if a child node exists at the key, false otherwise
81
81
  */
82
- has(key: ResourceName): boolean;
82
+ has(key: string): boolean;
83
83
  /**
84
84
  * Returns an iterator of ResourceName keys for all child nodes.
85
85
  * @returns Map iterator for all child node keys
@@ -37,7 +37,7 @@ const ts_utils_1 = require("@fgv/ts-utils");
37
37
  * strongly-typed internal tree operations, ensuring type safety and consistent
38
38
  * error handling throughout the resource tree navigation.
39
39
  *
40
- * @internal
40
+ * @public
41
41
  */
42
42
  class ResourceTreeChildrenValidator {
43
43
  /**
@@ -121,8 +121,8 @@ class ResourceTreeChildrenValidator {
121
121
  }
122
122
  }
123
123
  /**
124
- * Gets a child node by its ResourceName key with detailed error information.
125
- * @param key - The ResourceName key to look up
124
+ * Gets a child node by its string key with detailed error information.
125
+ * @param key - The string key to look up
126
126
  * @returns DetailedResult containing the node if found, or failure with details
127
127
  */
128
128
  get(key) {
@@ -132,8 +132,8 @@ class ResourceTreeChildrenValidator {
132
132
  return (0, ts_utils_1.failWithDetail)(`${key}: invalid resource name.`, 'invalid-key');
133
133
  }
134
134
  /**
135
- * Checks if a child node exists at the given ResourceName key.
136
- * @param key - The ResourceName key to check
135
+ * Checks if a child node exists at the given string key.
136
+ * @param key - The string key to check
137
137
  * @returns True if a child node exists at the key, false otherwise
138
138
  */
139
139
  has(key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-res",
3
- "version": "5.0.0-19",
3
+ "version": "5.0.0-20",
4
4
  "description": "Multi-dimensional Resource Runtime",
5
5
  "main": "lib/index.js",
6
6
  "types": "dist/ts-res.d.ts",
@@ -44,16 +44,16 @@
44
44
  "@rushstack/heft-node-rig": "~2.9.3",
45
45
  "@types/heft-jest": "1.0.6",
46
46
  "eslint-plugin-tsdoc": "~0.4.0",
47
- "@fgv/ts-utils-jest": "5.0.0-19",
48
- "@fgv/ts-extras": "5.0.0-19"
47
+ "@fgv/ts-utils-jest": "5.0.0-20",
48
+ "@fgv/ts-extras": "5.0.0-20"
49
49
  },
50
50
  "dependencies": {
51
51
  "luxon": "^3.7.1",
52
52
  "fflate": "~0.8.2",
53
- "@fgv/ts-utils": "5.0.0-19",
54
- "@fgv/ts-json": "5.0.0-19",
55
- "@fgv/ts-json-base": "5.0.0-19",
56
- "@fgv/ts-bcp47": "5.0.0-19"
53
+ "@fgv/ts-utils": "5.0.0-20",
54
+ "@fgv/ts-bcp47": "5.0.0-20",
55
+ "@fgv/ts-json-base": "5.0.0-20",
56
+ "@fgv/ts-json": "5.0.0-20"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "heft build --clean",
@@ -93,4 +93,12 @@ export class JsonResourceType extends ResourceType<JsonObject> {
93
93
  public validate(json: JsonObject, __completeness?: CandidateCompleteness): Result<JsonObject> {
94
94
  return JsonConverters.jsonObject.convert(json);
95
95
  }
96
+
97
+ /**
98
+ * Gets the default template value for a JSON resource type.
99
+ * @returns An empty object as the default JSON value
100
+ */
101
+ protected getDefaultTemplateValue(): JsonObject {
102
+ return {};
103
+ }
96
104
  }
@@ -20,7 +20,7 @@
20
20
  * SOFTWARE.
21
21
  */
22
22
 
23
- import { JsonValue } from '@fgv/ts-json-base';
23
+ import { JsonValue, JsonObject } from '@fgv/ts-json-base';
24
24
  import { Collections, ICollectible, Result } from '@fgv/ts-utils';
25
25
  import {
26
26
  CandidateCompleteness,
@@ -31,6 +31,7 @@ import {
31
31
  ResourceValueMergeMethod,
32
32
  ResourceId
33
33
  } from '../common';
34
+ import * as ResourceJson from '../resource-json';
34
35
 
35
36
  /**
36
37
  * Parameters used to validate a {@link ResourceJson.Json.ILooseResourceCandidateDecl | resource candidate declaration}.
@@ -123,6 +124,15 @@ export interface IResourceType<T = unknown> extends ICollectible<ResourceTypeNam
123
124
  * Sets the index for this resource type. Once set, the index cannot be changed.
124
125
  */
125
126
  setIndex(index: number): Result<ResourceTypeIndex>;
127
+
128
+ /**
129
+ * Creates a template for a new resource of this type.
130
+ * The template provides a default structure for creating new resource instances.
131
+ * @param resourceId - The id for the new resource
132
+ * @returns A loose resource declaration with default values for this resource type
133
+ * @public
134
+ */
135
+ createTemplate(resourceId: ResourceId): ResourceJson.Json.ILooseResourceDecl;
126
136
  }
127
137
 
128
138
  /**
@@ -212,4 +222,38 @@ export abstract class ResourceType<T = unknown> implements IResourceType<T> {
212
222
  public setIndex(index: number): Result<ResourceTypeIndex> {
213
223
  return this._collectible.setIndex(index);
214
224
  }
225
+
226
+ /**
227
+ * Creates a template for a new resource of this type.
228
+ * Default implementation provides a basic template.
229
+ * Subclasses can override to provide type-specific templates.
230
+ * @param resourceId - The id for the new resource
231
+ * @returns A loose resource declaration with default values for this resource type
232
+ * @public
233
+ */
234
+ public createTemplate(resourceId: ResourceId): ResourceJson.Json.ILooseResourceDecl {
235
+ return {
236
+ id: resourceId,
237
+ resourceTypeName: this.key,
238
+ candidates: [
239
+ {
240
+ json: this.getDefaultTemplateValue(),
241
+ conditions: undefined,
242
+ isPartial: false,
243
+ mergeMethod: 'replace'
244
+ }
245
+ ]
246
+ };
247
+ }
248
+
249
+ /**
250
+ * Gets the default template value for this resource type.
251
+ * Subclasses should override this to provide type-specific default values.
252
+ * @returns The default JSON value for a new resource of this type
253
+ */
254
+ protected getDefaultTemplateValue(): JsonObject {
255
+ // Default implementation returns an empty object
256
+ // Subclasses should override for type-specific defaults
257
+ return {};
258
+ }
215
259
  }
@@ -43,7 +43,7 @@ import {
43
43
  * strongly-typed internal tree operations, ensuring type safety and consistent
44
44
  * error handling throughout the resource tree navigation.
45
45
  *
46
- * @internal
46
+ * @public
47
47
  */
48
48
  export class ResourceTreeChildrenValidator<T> implements IReadOnlyResourceTreeChildren<T, string, string> {
49
49
  private readonly _inner: IReadOnlyResourceTreeChildren<T>;
@@ -141,13 +141,11 @@ export class ResourceTreeChildrenValidator<T> implements IReadOnlyResourceTreeCh
141
141
  }
142
142
 
143
143
  /**
144
- * Gets a child node by its ResourceName key with detailed error information.
145
- * @param key - The ResourceName key to look up
144
+ * Gets a child node by its string key with detailed error information.
145
+ * @param key - The string key to look up
146
146
  * @returns DetailedResult containing the node if found, or failure with details
147
147
  */
148
- public get(
149
- key: ResourceName
150
- ): DetailedResult<IReadOnlyResourceTreeNode<T>, Collections.ResultMapResultDetail> {
148
+ public get(key: string): DetailedResult<IReadOnlyResourceTreeNode<T>, Collections.ResultMapResultDetail> {
151
149
  if (Validate.isValidResourceName(key)) {
152
150
  return this._inner.get(key);
153
151
  }
@@ -155,11 +153,11 @@ export class ResourceTreeChildrenValidator<T> implements IReadOnlyResourceTreeCh
155
153
  }
156
154
 
157
155
  /**
158
- * Checks if a child node exists at the given ResourceName key.
159
- * @param key - The ResourceName key to check
156
+ * Checks if a child node exists at the given string key.
157
+ * @param key - The string key to check
160
158
  * @returns True if a child node exists at the key, false otherwise
161
159
  */
162
- public has(key: ResourceName): boolean {
160
+ public has(key: string): boolean {
163
161
  return this._inner.has(key as ResourceName);
164
162
  }
165
163