@twin.org/tools-core 0.0.2-next.4 → 0.0.2-next.6

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.
@@ -152,8 +152,10 @@ class JsonSchemaHelper {
152
152
  for (const typeKey of Object.keys(allSchemas)) {
153
153
  if (!referencedSchemas[typeKey]) {
154
154
  for (const requiredType of requiredTypes) {
155
- if ((core.Is.regexp(requiredType) && new RegExp(requiredType).test(typeKey)) ||
156
- (core.Is.stringValue(requiredType) && requiredType === typeKey)) {
155
+ const regex = requiredType.startsWith("/") && requiredType.endsWith("/")
156
+ ? new RegExp(requiredType.slice(1, -1))
157
+ : new RegExp(requiredType);
158
+ if (regex.test(typeKey)) {
157
159
  referencedSchemas[typeKey] = allSchemas[typeKey];
158
160
  JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
159
161
  }
@@ -182,7 +184,8 @@ class JsonSchemaHelper {
182
184
  if (core.Is.stringValue(schema.$ref)) {
183
185
  for (const expandedType of expandedTypes) {
184
186
  const typeName = JsonSchemaHelper.normaliseTypeName(schema.$ref.replace("#/definitions/", ""));
185
- if (new RegExp(expandedType).test(typeName) && allSchemas[typeName]) {
187
+ const regex = JsonSchemaHelper.autoExpandToRegEx(expandedType);
188
+ if (regex.test(typeName) && allSchemas[typeName]) {
186
189
  delete schema.$ref;
187
190
  Object.assign(schema, allSchemas[typeName]);
188
191
  break;
@@ -227,6 +230,16 @@ class JsonSchemaHelper {
227
230
  }
228
231
  }
229
232
  }
233
+ /**
234
+ * Convert a string auto expand pattern to a regular expression.
235
+ * @param autoExpand The auto expand pattern.
236
+ * @returns The regular expression.
237
+ */
238
+ static autoExpandToRegEx(autoExpand) {
239
+ return autoExpand.startsWith("/") && autoExpand.endsWith("/")
240
+ ? new RegExp(autoExpand.slice(1, -1))
241
+ : new RegExp(autoExpand);
242
+ }
230
243
  }
231
244
 
232
245
  // Copyright 2024 IOTA Stiftung.
@@ -150,8 +150,10 @@ class JsonSchemaHelper {
150
150
  for (const typeKey of Object.keys(allSchemas)) {
151
151
  if (!referencedSchemas[typeKey]) {
152
152
  for (const requiredType of requiredTypes) {
153
- if ((Is.regexp(requiredType) && new RegExp(requiredType).test(typeKey)) ||
154
- (Is.stringValue(requiredType) && requiredType === typeKey)) {
153
+ const regex = requiredType.startsWith("/") && requiredType.endsWith("/")
154
+ ? new RegExp(requiredType.slice(1, -1))
155
+ : new RegExp(requiredType);
156
+ if (regex.test(typeKey)) {
155
157
  referencedSchemas[typeKey] = allSchemas[typeKey];
156
158
  JsonSchemaHelper.extractTypesFromSchema(allSchemas, allSchemas[typeKey], referencedSchemas);
157
159
  }
@@ -180,7 +182,8 @@ class JsonSchemaHelper {
180
182
  if (Is.stringValue(schema.$ref)) {
181
183
  for (const expandedType of expandedTypes) {
182
184
  const typeName = JsonSchemaHelper.normaliseTypeName(schema.$ref.replace("#/definitions/", ""));
183
- if (new RegExp(expandedType).test(typeName) && allSchemas[typeName]) {
185
+ const regex = JsonSchemaHelper.autoExpandToRegEx(expandedType);
186
+ if (regex.test(typeName) && allSchemas[typeName]) {
184
187
  delete schema.$ref;
185
188
  Object.assign(schema, allSchemas[typeName]);
186
189
  break;
@@ -225,6 +228,16 @@ class JsonSchemaHelper {
225
228
  }
226
229
  }
227
230
  }
231
+ /**
232
+ * Convert a string auto expand pattern to a regular expression.
233
+ * @param autoExpand The auto expand pattern.
234
+ * @returns The regular expression.
235
+ */
236
+ static autoExpandToRegEx(autoExpand) {
237
+ return autoExpand.startsWith("/") && autoExpand.endsWith("/")
238
+ ? new RegExp(autoExpand.slice(1, -1))
239
+ : new RegExp(autoExpand);
240
+ }
228
241
  }
229
242
 
230
243
  // Copyright 2024 IOTA Stiftung.
@@ -49,7 +49,7 @@ export declare class JsonSchemaHelper {
49
49
  */
50
50
  static extractTypes(allSchemas: {
51
51
  [id: string]: IJsonSchema;
52
- }, requiredTypes: (string | RegExp)[], referencedSchemas: {
52
+ }, requiredTypes: string[], referencedSchemas: {
53
53
  [id: string]: IJsonSchema;
54
54
  }): void;
55
55
  /**
@@ -69,4 +69,10 @@ export declare class JsonSchemaHelper {
69
69
  static expandSchemaTypes(allSchemas: {
70
70
  [id: string]: IJsonSchema;
71
71
  }, schema: IJsonSchema, expandedTypes: string[]): void;
72
+ /**
73
+ * Convert a string auto expand pattern to a regular expression.
74
+ * @param autoExpand The auto expand pattern.
75
+ * @returns The regular expression.
76
+ */
77
+ static autoExpandToRegEx(autoExpand: string): RegExp;
72
78
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.2-next.6](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.5...tools-core-v0.0.2-next.6) (2025-08-21)
4
+
5
+
6
+ ### Features
7
+
8
+ * remove auto expanded types from final output ([18e05dc](https://github.com/twinfoundation/tools/commit/18e05dc88f71a0a27b79d1d076b1261b42d2c4c2))
9
+
10
+ ## [0.0.2-next.5](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.4...tools-core-v0.0.2-next.5) (2025-08-19)
11
+
12
+
13
+ ### Features
14
+
15
+ * correctly handle auto expand types ([57fce0f](https://github.com/twinfoundation/tools/commit/57fce0f9ec4a0876665d70adc6e885f6feb3caf7))
16
+
3
17
  ## [0.0.2-next.4](https://github.com/twinfoundation/tools/compare/tools-core-v0.0.2-next.3...tools-core-v0.0.2-next.4) (2025-08-19)
4
18
 
5
19
 
@@ -144,7 +144,7 @@ All the known schemas.
144
144
 
145
145
  ##### requiredTypes
146
146
 
147
- (`string` \| `RegExp`)[]
147
+ `string`[]
148
148
 
149
149
  The required types.
150
150
 
@@ -209,3 +209,25 @@ The types to expand.
209
209
  #### Returns
210
210
 
211
211
  `void`
212
+
213
+ ***
214
+
215
+ ### autoExpandToRegEx()
216
+
217
+ > `static` **autoExpandToRegEx**(`autoExpand`): `RegExp`
218
+
219
+ Convert a string auto expand pattern to a regular expression.
220
+
221
+ #### Parameters
222
+
223
+ ##### autoExpand
224
+
225
+ `string`
226
+
227
+ The auto expand pattern.
228
+
229
+ #### Returns
230
+
231
+ `RegExp`
232
+
233
+ The regular expression.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/tools-core",
3
- "version": "0.0.2-next.4",
3
+ "version": "0.0.2-next.6",
4
4
  "description": "Shared components for the tools",
5
5
  "repository": {
6
6
  "type": "git",