@twin.org/tools-core 0.0.3-next.2 → 0.0.3-next.21
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/README.md +2 -2
- package/dist/es/index.js +20 -11
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ITypeScriptToSchemaContext.js +2 -0
- package/dist/es/models/ITypeScriptToSchemaContext.js.map +1 -0
- package/dist/es/models/ITypeScriptToSchemaDiagnostics.js +4 -0
- package/dist/es/models/ITypeScriptToSchemaDiagnostics.js.map +1 -0
- package/dist/es/models/ITypeScriptToSchemaOptions.js +4 -0
- package/dist/es/models/ITypeScriptToSchemaOptions.js.map +1 -0
- package/dist/es/utils/constants.js +43 -0
- package/dist/es/utils/constants.js.map +1 -0
- package/dist/es/utils/diagnosticReporter.js +32 -0
- package/dist/es/utils/diagnosticReporter.js.map +1 -0
- package/dist/es/utils/disallowedTypeGuard.js +151 -0
- package/dist/es/utils/disallowedTypeGuard.js.map +1 -0
- package/dist/es/utils/enum.js +152 -0
- package/dist/es/utils/enum.js.map +1 -0
- package/dist/es/utils/fileUtils.js +130 -0
- package/dist/es/utils/fileUtils.js.map +1 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js +328 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js.map +1 -0
- package/dist/es/utils/indexSignaturePatternResolver.js +94 -0
- package/dist/es/utils/indexSignaturePatternResolver.js.map +1 -0
- package/dist/es/utils/intersectionSchemaMerger.js +85 -0
- package/dist/es/utils/intersectionSchemaMerger.js.map +1 -0
- package/dist/es/utils/jsDoc.js +120 -0
- package/dist/es/utils/jsDoc.js.map +1 -0
- package/dist/es/utils/jsonSchemaBuilder.js +3373 -0
- package/dist/es/utils/jsonSchemaBuilder.js.map +1 -0
- package/dist/es/utils/mappedTypeSchemaResolver.js +231 -0
- package/dist/es/utils/mappedTypeSchemaResolver.js.map +1 -0
- package/dist/es/utils/objectTransformer.js +162 -0
- package/dist/es/utils/objectTransformer.js.map +1 -0
- package/dist/es/utils/regEx.js +128 -0
- package/dist/es/utils/regEx.js.map +1 -0
- package/dist/es/utils/resolver.js +164 -0
- package/dist/es/utils/resolver.js.map +1 -0
- package/dist/es/utils/templateLiteralPatternBuilder.js +94 -0
- package/dist/es/utils/templateLiteralPatternBuilder.js.map +1 -0
- package/dist/es/utils/typeScriptToSchema.js +112 -0
- package/dist/es/utils/typeScriptToSchema.js.map +1 -0
- package/dist/es/utils/utilityTypeSchemaMapper.js +412 -0
- package/dist/es/utils/utilityTypeSchemaMapper.js.map +1 -0
- package/dist/types/index.d.ts +20 -11
- package/dist/types/models/ITypeScriptToSchemaContext.d.ts +64 -0
- package/dist/types/models/ITypeScriptToSchemaDiagnostics.d.ts +31 -0
- package/dist/types/models/ITypeScriptToSchemaOptions.d.ts +22 -0
- package/dist/types/utils/constants.d.ts +13 -0
- package/dist/types/utils/diagnosticReporter.d.ts +17 -0
- package/dist/types/utils/disallowedTypeGuard.d.ts +16 -0
- package/dist/types/utils/enum.d.ts +42 -0
- package/dist/types/utils/fileUtils.d.ts +66 -0
- package/dist/types/utils/importTypeQuerySchemaResolver.d.ts +52 -0
- package/dist/types/utils/indexSignaturePatternResolver.d.ts +21 -0
- package/dist/types/utils/intersectionSchemaMerger.d.ts +16 -0
- package/dist/types/utils/jsDoc.d.ts +46 -0
- package/dist/types/utils/jsonSchemaBuilder.d.ts +747 -0
- package/dist/types/utils/mappedTypeSchemaResolver.d.ts +46 -0
- package/dist/types/utils/objectTransformer.d.ts +33 -0
- package/dist/types/utils/regEx.d.ts +24 -0
- package/dist/types/utils/resolver.d.ts +16 -0
- package/dist/types/utils/templateLiteralPatternBuilder.d.ts +12 -0
- package/dist/types/utils/typeScriptToSchema.d.ts +31 -0
- package/dist/types/utils/utilityTypeSchemaMapper.d.ts +92 -0
- package/docs/changelog.md +176 -1
- package/docs/examples.md +87 -1
- package/docs/reference/classes/Constants.md +29 -0
- package/docs/reference/classes/DiagnosticReporter.md +49 -0
- package/docs/reference/classes/DisallowedTypeGuard.md +35 -0
- package/docs/reference/classes/Enum.md +93 -0
- package/docs/reference/classes/FileUtils.md +237 -0
- package/docs/reference/classes/ImportTypeQuerySchemaResolver.md +87 -0
- package/docs/reference/classes/IndexSignaturePatternResolver.md +69 -0
- package/docs/reference/classes/IntersectionSchemaMerger.md +48 -0
- package/docs/reference/classes/JsDoc.md +141 -0
- package/docs/reference/classes/JsonSchemaBuilder.md +2870 -0
- package/docs/reference/classes/MappedTypeSchemaResolver.md +211 -0
- package/docs/reference/classes/ObjectTransformer.md +119 -0
- package/docs/reference/classes/RegEx.md +99 -0
- package/docs/reference/classes/Resolver.md +41 -0
- package/docs/reference/classes/TemplateLiteralPatternBuilder.md +35 -0
- package/docs/reference/classes/TypeScriptToSchema.md +91 -0
- package/docs/reference/classes/UtilityTypeSchemaMapper.md +341 -0
- package/docs/reference/index.md +20 -14
- package/docs/reference/interfaces/ITypeScriptToSchemaContext.md +113 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaDiagnostics.md +55 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaOptions.md +44 -0
- package/locales/en.json +32 -1
- package/package.json +4 -3
- package/dist/es/models/IJsonSchema.js +0 -2
- package/dist/es/models/IJsonSchema.js.map +0 -1
- package/dist/es/models/IOpenApi.js +0 -2
- package/dist/es/models/IOpenApi.js.map +0 -1
- package/dist/es/models/IOpenApiExample.js +0 -4
- package/dist/es/models/IOpenApiExample.js.map +0 -1
- package/dist/es/models/IOpenApiHeader.js +0 -4
- package/dist/es/models/IOpenApiHeader.js.map +0 -1
- package/dist/es/models/IOpenApiPathMethod.js +0 -2
- package/dist/es/models/IOpenApiPathMethod.js.map +0 -1
- package/dist/es/models/IOpenApiResponse.js +0 -2
- package/dist/es/models/IOpenApiResponse.js.map +0 -1
- package/dist/es/models/IOpenApiSecurityScheme.js +0 -4
- package/dist/es/models/IOpenApiSecurityScheme.js.map +0 -1
- package/dist/es/models/IPackageJson.js +0 -4
- package/dist/es/models/IPackageJson.js.map +0 -1
- package/dist/es/models/jsonTypeName.js +0 -2
- package/dist/es/models/jsonTypeName.js.map +0 -1
- package/dist/es/utils/jsonSchemaHelper.js +0 -258
- package/dist/es/utils/jsonSchemaHelper.js.map +0 -1
- package/dist/es/utils/openApiHelper.js +0 -12
- package/dist/es/utils/openApiHelper.js.map +0 -1
- package/dist/types/models/IJsonSchema.d.ts +0 -5
- package/dist/types/models/IOpenApi.d.ts +0 -54
- package/dist/types/models/IOpenApiExample.d.ts +0 -13
- package/dist/types/models/IOpenApiHeader.d.ts +0 -19
- package/dist/types/models/IOpenApiPathMethod.d.ts +0 -65
- package/dist/types/models/IOpenApiResponse.d.ts +0 -32
- package/dist/types/models/IOpenApiSecurityScheme.d.ts +0 -25
- package/dist/types/models/IPackageJson.d.ts +0 -15
- package/dist/types/models/jsonTypeName.d.ts +0 -5
- package/dist/types/utils/jsonSchemaHelper.d.ts +0 -78
- package/dist/types/utils/openApiHelper.d.ts +0 -9
- package/docs/reference/classes/JsonSchemaHelper.md +0 -233
- package/docs/reference/classes/OpenApiHelper.md +0 -21
- package/docs/reference/interfaces/IOpenApi.md +0 -103
- package/docs/reference/interfaces/IOpenApiExample.md +0 -19
- package/docs/reference/interfaces/IOpenApiHeader.md +0 -31
- package/docs/reference/interfaces/IOpenApiPathMethod.md +0 -119
- package/docs/reference/interfaces/IOpenApiResponse.md +0 -35
- package/docs/reference/interfaces/IOpenApiSecurityScheme.md +0 -43
- package/docs/reference/interfaces/IPackageJson.md +0 -23
- package/docs/reference/type-aliases/IJsonSchema.md +0 -5
- package/docs/reference/type-aliases/JsonTypeName.md +0 -5
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# Class: UtilityTypeSchemaMapper
|
|
2
|
+
|
|
3
|
+
Static utility-type schema mapping helpers.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### Constructor
|
|
8
|
+
|
|
9
|
+
> **new UtilityTypeSchemaMapper**(): `UtilityTypeSchemaMapper`
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
`UtilityTypeSchemaMapper`
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### mapPartialUtilityType() {#mappartialutilitytype}
|
|
18
|
+
|
|
19
|
+
> `static` **mapPartialUtilityType**(`context`, `typeNode`, `resolveUtilityBaseObjectSchema`): `IJsonSchema` \| `undefined`
|
|
20
|
+
|
|
21
|
+
Map Partial<T> to an object schema with no required properties.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
##### context
|
|
26
|
+
|
|
27
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
28
|
+
|
|
29
|
+
The generation context.
|
|
30
|
+
|
|
31
|
+
##### typeNode
|
|
32
|
+
|
|
33
|
+
`TypeReferenceNode`
|
|
34
|
+
|
|
35
|
+
The Partial type reference.
|
|
36
|
+
|
|
37
|
+
##### resolveUtilityBaseObjectSchema
|
|
38
|
+
|
|
39
|
+
(`context`, `baseTypeNode`) => `IJsonSchema` \| `undefined`
|
|
40
|
+
|
|
41
|
+
Callback to resolve base object schemas.
|
|
42
|
+
|
|
43
|
+
#### Returns
|
|
44
|
+
|
|
45
|
+
`IJsonSchema` \| `undefined`
|
|
46
|
+
|
|
47
|
+
The mapped schema.
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
### mapRequiredUtilityType() {#maprequiredutilitytype}
|
|
52
|
+
|
|
53
|
+
> `static` **mapRequiredUtilityType**(`context`, `typeNode`, `resolveUtilityBaseObjectSchema`): `IJsonSchema` \| `undefined`
|
|
54
|
+
|
|
55
|
+
Map Required<T> to an object schema with all properties required.
|
|
56
|
+
|
|
57
|
+
#### Parameters
|
|
58
|
+
|
|
59
|
+
##### context
|
|
60
|
+
|
|
61
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
62
|
+
|
|
63
|
+
The generation context.
|
|
64
|
+
|
|
65
|
+
##### typeNode
|
|
66
|
+
|
|
67
|
+
`TypeReferenceNode`
|
|
68
|
+
|
|
69
|
+
The Required type reference.
|
|
70
|
+
|
|
71
|
+
##### resolveUtilityBaseObjectSchema
|
|
72
|
+
|
|
73
|
+
(`context`, `baseTypeNode`) => `IJsonSchema` \| `undefined`
|
|
74
|
+
|
|
75
|
+
Callback to resolve base object schemas.
|
|
76
|
+
|
|
77
|
+
#### Returns
|
|
78
|
+
|
|
79
|
+
`IJsonSchema` \| `undefined`
|
|
80
|
+
|
|
81
|
+
The mapped schema.
|
|
82
|
+
|
|
83
|
+
***
|
|
84
|
+
|
|
85
|
+
### mapPickUtilityType() {#mappickutilitytype}
|
|
86
|
+
|
|
87
|
+
> `static` **mapPickUtilityType**(`context`, `typeNode`, `resolveUtilityBaseObjectSchema`, `extractUtilityTypeKeys`): `IJsonSchema` \| `undefined`
|
|
88
|
+
|
|
89
|
+
Map Pick<T, K> to an object schema with selected keys preserved.
|
|
90
|
+
|
|
91
|
+
#### Parameters
|
|
92
|
+
|
|
93
|
+
##### context
|
|
94
|
+
|
|
95
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
96
|
+
|
|
97
|
+
##### typeNode
|
|
98
|
+
|
|
99
|
+
`TypeReferenceNode`
|
|
100
|
+
|
|
101
|
+
##### resolveUtilityBaseObjectSchema
|
|
102
|
+
|
|
103
|
+
(`context`, `baseTypeNode`) => `IJsonSchema` \| `undefined`
|
|
104
|
+
|
|
105
|
+
##### extractUtilityTypeKeys
|
|
106
|
+
|
|
107
|
+
(`context`, `keysNode`) => `string`[]
|
|
108
|
+
|
|
109
|
+
#### Returns
|
|
110
|
+
|
|
111
|
+
`IJsonSchema` \| `undefined`
|
|
112
|
+
|
|
113
|
+
***
|
|
114
|
+
|
|
115
|
+
### mapOmitUtilityType() {#mapomitutilitytype}
|
|
116
|
+
|
|
117
|
+
> `static` **mapOmitUtilityType**(`context`, `typeNode`, `resolveUtilityBaseObjectSchema`, `extractUtilityTypeKeys`): `IJsonSchema` \| `undefined`
|
|
118
|
+
|
|
119
|
+
Map Omit<T, K> to an object schema with selected keys removed.
|
|
120
|
+
|
|
121
|
+
#### Parameters
|
|
122
|
+
|
|
123
|
+
##### context
|
|
124
|
+
|
|
125
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
126
|
+
|
|
127
|
+
##### typeNode
|
|
128
|
+
|
|
129
|
+
`TypeReferenceNode`
|
|
130
|
+
|
|
131
|
+
##### resolveUtilityBaseObjectSchema
|
|
132
|
+
|
|
133
|
+
(`context`, `baseTypeNode`) => `IJsonSchema` \| `undefined`
|
|
134
|
+
|
|
135
|
+
##### extractUtilityTypeKeys
|
|
136
|
+
|
|
137
|
+
(`context`, `keysNode`) => `string`[]
|
|
138
|
+
|
|
139
|
+
#### Returns
|
|
140
|
+
|
|
141
|
+
`IJsonSchema` \| `undefined`
|
|
142
|
+
|
|
143
|
+
***
|
|
144
|
+
|
|
145
|
+
### mapExcludeUtilityType() {#mapexcludeutilitytype}
|
|
146
|
+
|
|
147
|
+
> `static` **mapExcludeUtilityType**(`context`, `typeNode`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
148
|
+
|
|
149
|
+
Map Exclude<T, U> to a schema that removes U members from T.
|
|
150
|
+
|
|
151
|
+
#### Parameters
|
|
152
|
+
|
|
153
|
+
##### context
|
|
154
|
+
|
|
155
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
156
|
+
|
|
157
|
+
##### typeNode
|
|
158
|
+
|
|
159
|
+
`TypeReferenceNode`
|
|
160
|
+
|
|
161
|
+
##### mapTypeNodeToSchema
|
|
162
|
+
|
|
163
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
164
|
+
|
|
165
|
+
#### Returns
|
|
166
|
+
|
|
167
|
+
`IJsonSchema` \| `undefined`
|
|
168
|
+
|
|
169
|
+
***
|
|
170
|
+
|
|
171
|
+
### mapExtractUtilityType() {#mapextractutilitytype}
|
|
172
|
+
|
|
173
|
+
> `static` **mapExtractUtilityType**(`context`, `typeNode`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
174
|
+
|
|
175
|
+
Map Extract<T, U> to a schema that keeps U members from T.
|
|
176
|
+
|
|
177
|
+
#### Parameters
|
|
178
|
+
|
|
179
|
+
##### context
|
|
180
|
+
|
|
181
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
182
|
+
|
|
183
|
+
##### typeNode
|
|
184
|
+
|
|
185
|
+
`TypeReferenceNode`
|
|
186
|
+
|
|
187
|
+
##### mapTypeNodeToSchema
|
|
188
|
+
|
|
189
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
190
|
+
|
|
191
|
+
#### Returns
|
|
192
|
+
|
|
193
|
+
`IJsonSchema` \| `undefined`
|
|
194
|
+
|
|
195
|
+
***
|
|
196
|
+
|
|
197
|
+
### mapNonNullableUtilityType() {#mapnonnullableutilitytype}
|
|
198
|
+
|
|
199
|
+
> `static` **mapNonNullableUtilityType**(`context`, `typeNode`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
200
|
+
|
|
201
|
+
Map NonNullable<T> by removing null and undefined branches from T.
|
|
202
|
+
|
|
203
|
+
#### Parameters
|
|
204
|
+
|
|
205
|
+
##### context
|
|
206
|
+
|
|
207
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
208
|
+
|
|
209
|
+
##### typeNode
|
|
210
|
+
|
|
211
|
+
`TypeReferenceNode`
|
|
212
|
+
|
|
213
|
+
##### mapTypeNodeToSchema
|
|
214
|
+
|
|
215
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
216
|
+
|
|
217
|
+
#### Returns
|
|
218
|
+
|
|
219
|
+
`IJsonSchema` \| `undefined`
|
|
220
|
+
|
|
221
|
+
***
|
|
222
|
+
|
|
223
|
+
### mapRecordUtilityType() {#maprecordutilitytype}
|
|
224
|
+
|
|
225
|
+
> `static` **mapRecordUtilityType**(`context`, `typeNode`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
226
|
+
|
|
227
|
+
Map Record<K, V> to an object schema with key constraints where possible.
|
|
228
|
+
|
|
229
|
+
#### Parameters
|
|
230
|
+
|
|
231
|
+
##### context
|
|
232
|
+
|
|
233
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
234
|
+
|
|
235
|
+
##### typeNode
|
|
236
|
+
|
|
237
|
+
`TypeReferenceNode`
|
|
238
|
+
|
|
239
|
+
##### mapTypeNodeToSchema
|
|
240
|
+
|
|
241
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
242
|
+
|
|
243
|
+
#### Returns
|
|
244
|
+
|
|
245
|
+
`IJsonSchema` \| `undefined`
|
|
246
|
+
|
|
247
|
+
***
|
|
248
|
+
|
|
249
|
+
### mapJsonLdObjectUtilityType() {#mapjsonldobjectutilitytype}
|
|
250
|
+
|
|
251
|
+
> `static` **mapJsonLdObjectUtilityType**(`context`, `typeNode`, `options`, `resolveUtilityBaseObjectSchema`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
252
|
+
|
|
253
|
+
Map JsonLdObject utility types using key-removal and optional key-addition rules.
|
|
254
|
+
|
|
255
|
+
#### Parameters
|
|
256
|
+
|
|
257
|
+
##### context
|
|
258
|
+
|
|
259
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
260
|
+
|
|
261
|
+
##### typeNode
|
|
262
|
+
|
|
263
|
+
`TypeReferenceNode`
|
|
264
|
+
|
|
265
|
+
##### options
|
|
266
|
+
|
|
267
|
+
###### keysToRemove
|
|
268
|
+
|
|
269
|
+
`string`[]
|
|
270
|
+
|
|
271
|
+
###### keyToAdd?
|
|
272
|
+
|
|
273
|
+
`"type"` \| `"id"` \| `"@id"` \| `"@type"` \| `"@context"`
|
|
274
|
+
|
|
275
|
+
###### isAddedKeyRequired?
|
|
276
|
+
|
|
277
|
+
`boolean`
|
|
278
|
+
|
|
279
|
+
##### resolveUtilityBaseObjectSchema
|
|
280
|
+
|
|
281
|
+
(`context`, `baseTypeNode`) => `IJsonSchema` \| `undefined`
|
|
282
|
+
|
|
283
|
+
##### mapTypeNodeToSchema
|
|
284
|
+
|
|
285
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
286
|
+
|
|
287
|
+
#### Returns
|
|
288
|
+
|
|
289
|
+
`IJsonSchema` \| `undefined`
|
|
290
|
+
|
|
291
|
+
***
|
|
292
|
+
|
|
293
|
+
### mapObjectOrArrayUtilityType() {#mapobjectorarrayutilitytype}
|
|
294
|
+
|
|
295
|
+
> `static` **mapObjectOrArrayUtilityType**(`context`, `typeNode`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
296
|
+
|
|
297
|
+
Map ObjectOrArray<T> to a schema accepting T or T[].
|
|
298
|
+
|
|
299
|
+
#### Parameters
|
|
300
|
+
|
|
301
|
+
##### context
|
|
302
|
+
|
|
303
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
304
|
+
|
|
305
|
+
##### typeNode
|
|
306
|
+
|
|
307
|
+
`TypeReferenceNode`
|
|
308
|
+
|
|
309
|
+
##### mapTypeNodeToSchema
|
|
310
|
+
|
|
311
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
312
|
+
|
|
313
|
+
#### Returns
|
|
314
|
+
|
|
315
|
+
`IJsonSchema` \| `undefined`
|
|
316
|
+
|
|
317
|
+
***
|
|
318
|
+
|
|
319
|
+
### mapSingleOccurrenceArrayUtilityType() {#mapsingleoccurrencearrayutilitytype}
|
|
320
|
+
|
|
321
|
+
> `static` **mapSingleOccurrenceArrayUtilityType**(`context`, `typeNode`, `mapTypeNodeToSchema`): `IJsonSchema` \| `undefined`
|
|
322
|
+
|
|
323
|
+
Map SingleOccurrenceArray<T, U> to a non-empty array containing exactly one U.
|
|
324
|
+
|
|
325
|
+
#### Parameters
|
|
326
|
+
|
|
327
|
+
##### context
|
|
328
|
+
|
|
329
|
+
[`ITypeScriptToSchemaContext`](../interfaces/ITypeScriptToSchemaContext.md)
|
|
330
|
+
|
|
331
|
+
##### typeNode
|
|
332
|
+
|
|
333
|
+
`TypeReferenceNode`
|
|
334
|
+
|
|
335
|
+
##### mapTypeNodeToSchema
|
|
336
|
+
|
|
337
|
+
(`context`, `typeNode`) => `IJsonSchema` \| `undefined`
|
|
338
|
+
|
|
339
|
+
#### Returns
|
|
340
|
+
|
|
341
|
+
`IJsonSchema` \| `undefined`
|
package/docs/reference/index.md
CHANGED
|
@@ -2,20 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
## Classes
|
|
4
4
|
|
|
5
|
-
- [
|
|
6
|
-
- [
|
|
5
|
+
- [Constants](classes/Constants.md)
|
|
6
|
+
- [DiagnosticReporter](classes/DiagnosticReporter.md)
|
|
7
|
+
- [DisallowedTypeGuard](classes/DisallowedTypeGuard.md)
|
|
8
|
+
- [Enum](classes/Enum.md)
|
|
9
|
+
- [FileUtils](classes/FileUtils.md)
|
|
10
|
+
- [ImportTypeQuerySchemaResolver](classes/ImportTypeQuerySchemaResolver.md)
|
|
11
|
+
- [IndexSignaturePatternResolver](classes/IndexSignaturePatternResolver.md)
|
|
12
|
+
- [IntersectionSchemaMerger](classes/IntersectionSchemaMerger.md)
|
|
13
|
+
- [JsDoc](classes/JsDoc.md)
|
|
14
|
+
- [JsonSchemaBuilder](classes/JsonSchemaBuilder.md)
|
|
15
|
+
- [MappedTypeSchemaResolver](classes/MappedTypeSchemaResolver.md)
|
|
16
|
+
- [ObjectTransformer](classes/ObjectTransformer.md)
|
|
17
|
+
- [RegEx](classes/RegEx.md)
|
|
18
|
+
- [Resolver](classes/Resolver.md)
|
|
19
|
+
- [TemplateLiteralPatternBuilder](classes/TemplateLiteralPatternBuilder.md)
|
|
20
|
+
- [TypeScriptToSchema](classes/TypeScriptToSchema.md)
|
|
21
|
+
- [UtilityTypeSchemaMapper](classes/UtilityTypeSchemaMapper.md)
|
|
7
22
|
|
|
8
23
|
## Interfaces
|
|
9
24
|
|
|
10
|
-
- [
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
13
|
-
- [IOpenApiPathMethod](interfaces/IOpenApiPathMethod.md)
|
|
14
|
-
- [IOpenApiResponse](interfaces/IOpenApiResponse.md)
|
|
15
|
-
- [IOpenApiSecurityScheme](interfaces/IOpenApiSecurityScheme.md)
|
|
16
|
-
- [IPackageJson](interfaces/IPackageJson.md)
|
|
17
|
-
|
|
18
|
-
## Type Aliases
|
|
19
|
-
|
|
20
|
-
- [IJsonSchema](type-aliases/IJsonSchema.md)
|
|
21
|
-
- [JsonTypeName](type-aliases/JsonTypeName.md)
|
|
25
|
+
- [ITypeScriptToSchemaContext](interfaces/ITypeScriptToSchemaContext.md)
|
|
26
|
+
- [ITypeScriptToSchemaDiagnostics](interfaces/ITypeScriptToSchemaDiagnostics.md)
|
|
27
|
+
- [ITypeScriptToSchemaOptions](interfaces/ITypeScriptToSchemaOptions.md)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Interface: ITypeScriptToSchemaContext
|
|
2
|
+
|
|
3
|
+
Context for TypeScript to JSON schema generation.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### namespace {#namespace}
|
|
8
|
+
|
|
9
|
+
> **namespace**: `string`
|
|
10
|
+
|
|
11
|
+
The namespace for generated schema ids.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### packageName {#packagename}
|
|
16
|
+
|
|
17
|
+
> **packageName**: `string`
|
|
18
|
+
|
|
19
|
+
The package name for generated schema ids.
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### schemas {#schemas}
|
|
24
|
+
|
|
25
|
+
> **schemas**: `object`
|
|
26
|
+
|
|
27
|
+
The schema cache indexed by package and title.
|
|
28
|
+
|
|
29
|
+
#### Index Signature
|
|
30
|
+
|
|
31
|
+
\[`id`: `string`\]: `object`
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### activeSourceFile? {#activesourcefile}
|
|
36
|
+
|
|
37
|
+
> `optional` **activeSourceFile?**: `SourceFile`
|
|
38
|
+
|
|
39
|
+
The currently active source file being mapped.
|
|
40
|
+
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
### activeEnclosingObjectName? {#activeenclosingobjectname}
|
|
44
|
+
|
|
45
|
+
> `optional` **activeEnclosingObjectName?**: `string`
|
|
46
|
+
|
|
47
|
+
The currently active enclosing object (interface/type) being mapped.
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
### activeDisallowedType? {#activedisallowedtype}
|
|
52
|
+
|
|
53
|
+
> `optional` **activeDisallowedType?**: `object`
|
|
54
|
+
|
|
55
|
+
The first disallowed type encountered while mapping the active enclosing object.
|
|
56
|
+
|
|
57
|
+
#### disallowedTypeName
|
|
58
|
+
|
|
59
|
+
> **disallowedTypeName**: `string`
|
|
60
|
+
|
|
61
|
+
#### propertyName
|
|
62
|
+
|
|
63
|
+
> **propertyName**: `string`
|
|
64
|
+
|
|
65
|
+
#### enclosingObjectName
|
|
66
|
+
|
|
67
|
+
> **enclosingObjectName**: `string`
|
|
68
|
+
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
### resolvingTypeNames? {#resolvingtypenames}
|
|
72
|
+
|
|
73
|
+
> `optional` **resolvingTypeNames?**: `Set`\<`string`\>
|
|
74
|
+
|
|
75
|
+
Type names currently being resolved to avoid recursive local-type expansion loops.
|
|
76
|
+
|
|
77
|
+
***
|
|
78
|
+
|
|
79
|
+
### resolvingUtilityTypes? {#resolvingutilitytypes}
|
|
80
|
+
|
|
81
|
+
> `optional` **resolvingUtilityTypes?**: `Set`\<`string`\>
|
|
82
|
+
|
|
83
|
+
Utility type names currently being processed to avoid infinite recursion cycles
|
|
84
|
+
when encountering complex combinations of indexed access types, keyof, and utility types.
|
|
85
|
+
|
|
86
|
+
***
|
|
87
|
+
|
|
88
|
+
### resolvingImportedObjectSchemas? {#resolvingimportedobjectschemas}
|
|
89
|
+
|
|
90
|
+
> `optional` **resolvingImportedObjectSchemas?**: `Set`\<`string`\>
|
|
91
|
+
|
|
92
|
+
Imported utility base schemas currently being resolved to avoid recursive re-entry
|
|
93
|
+
while parsing module graphs for utility type application.
|
|
94
|
+
|
|
95
|
+
***
|
|
96
|
+
|
|
97
|
+
### typeParameterBindings? {#typeparameterbindings}
|
|
98
|
+
|
|
99
|
+
> `optional` **typeParameterBindings?**: `object`
|
|
100
|
+
|
|
101
|
+
Generic type parameter bindings active for the current mapping scope.
|
|
102
|
+
|
|
103
|
+
#### Index Signature
|
|
104
|
+
|
|
105
|
+
\[`id`: `string`\]: `TypeNode` \| `null`
|
|
106
|
+
|
|
107
|
+
***
|
|
108
|
+
|
|
109
|
+
### options? {#options}
|
|
110
|
+
|
|
111
|
+
> `optional` **options?**: [`ITypeScriptToSchemaOptions`](ITypeScriptToSchemaOptions.md)
|
|
112
|
+
|
|
113
|
+
Optional schema generation options.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Interface: ITypeScriptToSchemaDiagnostics
|
|
2
|
+
|
|
3
|
+
Diagnostic payload for non-fatal schema generation issues.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### code {#code}
|
|
8
|
+
|
|
9
|
+
> **code**: `string`
|
|
10
|
+
|
|
11
|
+
Stable diagnostic code identifying the issue type.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### properties? {#properties}
|
|
16
|
+
|
|
17
|
+
> `optional` **properties?**: `object`
|
|
18
|
+
|
|
19
|
+
Additional structured metadata related to the diagnostic.
|
|
20
|
+
|
|
21
|
+
#### Index Signature
|
|
22
|
+
|
|
23
|
+
\[`key`: `string`\]: `unknown`
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### path {#path}
|
|
28
|
+
|
|
29
|
+
> **path**: `string`
|
|
30
|
+
|
|
31
|
+
Schema path where the issue was detected.
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### fileName? {#filename}
|
|
36
|
+
|
|
37
|
+
> `optional` **fileName?**: `string`
|
|
38
|
+
|
|
39
|
+
Source file where the diagnostic originated, if available.
|
|
40
|
+
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
### line? {#line}
|
|
44
|
+
|
|
45
|
+
> `optional` **line?**: `number`
|
|
46
|
+
|
|
47
|
+
One-based source line number, when available.
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
### column? {#column}
|
|
52
|
+
|
|
53
|
+
> `optional` **column?**: `number`
|
|
54
|
+
|
|
55
|
+
One-based source column number, when available.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Interface: ITypeScriptToSchemaOptions
|
|
2
|
+
|
|
3
|
+
Options for TypeScript to JSON schema generation.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### externalReferences? {#externalreferences}
|
|
8
|
+
|
|
9
|
+
> `optional` **externalReferences?**: `object`
|
|
10
|
+
|
|
11
|
+
Mapping of package ids, type ids, wildcard patterns, or regex patterns to schema id prefixes
|
|
12
|
+
or replacement templates for referenced schemas.
|
|
13
|
+
|
|
14
|
+
#### Index Signature
|
|
15
|
+
|
|
16
|
+
\[`id`: `string`\]: `string`
|
|
17
|
+
|
|
18
|
+
***
|
|
19
|
+
|
|
20
|
+
### onDiagnostic? {#ondiagnostic}
|
|
21
|
+
|
|
22
|
+
> `optional` **onDiagnostic?**: (`diagnostic`) => `void`
|
|
23
|
+
|
|
24
|
+
Optional diagnostic callback for non-fatal generation issues.
|
|
25
|
+
|
|
26
|
+
#### Parameters
|
|
27
|
+
|
|
28
|
+
##### diagnostic
|
|
29
|
+
|
|
30
|
+
[`ITypeScriptToSchemaDiagnostics`](ITypeScriptToSchemaDiagnostics.md)
|
|
31
|
+
|
|
32
|
+
The diagnostic details for the generation issue.
|
|
33
|
+
|
|
34
|
+
#### Returns
|
|
35
|
+
|
|
36
|
+
`void`
|
|
37
|
+
|
|
38
|
+
***
|
|
39
|
+
|
|
40
|
+
### suppressPackageWarnings? {#suppresspackagewarnings}
|
|
41
|
+
|
|
42
|
+
> `optional` **suppressPackageWarnings?**: `string`[]
|
|
43
|
+
|
|
44
|
+
Package names where diagnostics should be suppressed, e.g. jose.
|
package/locales/en.json
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
"error": {
|
|
2
|
+
"error": {
|
|
3
|
+
"jsonSchemaBuilder": {
|
|
4
|
+
"invalidJsonSchemaTagKey": "Ignoring invalid @json-schema tag key \"{rawKey}\". Mapped key \"{schemaKey}\" is not supported by JSON Schema.",
|
|
5
|
+
"constraintOnIncompatibleType": "The @json-schema \"{schemaKey}\" constraint requires type \"{requiredType}\" but the type is \"{schemaType}\".",
|
|
6
|
+
"invalidFormatValue": "The @json-schema \"format\" value \"{formatValue}\" is not a recognised JSON Schema format. Valid values are: {validFormats}.",
|
|
7
|
+
"missingTypeReferenceSchema": "Unable to resolve type \"{typeName}\"{importSource} required as base type for utility type. Ensure the type is in the configured packages list or its external package exports TypeScript source files that can be parsed via the AST."
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"jsonSchemaBuilder": {
|
|
11
|
+
"diagnostic": {
|
|
12
|
+
"symbolValuedProperty": "Skipping symbol-typed property \"{propertyName}\".",
|
|
13
|
+
"symbolKeyedMember": "Skipping symbol-keyed member \"{memberName}\".",
|
|
14
|
+
"unsupportedComputedPropertyName": "Skipping unsupported computed property name \"{propertyName}\".",
|
|
15
|
+
"functionTypedProperty": "Skipping function-typed property \"{propertyName}\".",
|
|
16
|
+
"unsupportedIndexSignature": "Skipping index signature with unsupported key type \"{keyType}\".",
|
|
17
|
+
"unresolvedKeyofOperand": "Could not resolve keyof operand \"{operand}\".",
|
|
18
|
+
"unmappedTypeNode": "Unsupported TypeScript type node kind \"{kind}\"; the type will be omitted.",
|
|
19
|
+
"unresolvedMappedTypeRemap": "Could not resolve mapped type key remap for \"{typeName}\"; falling back to additionalProperties.",
|
|
20
|
+
"unsupportedImportTypeForm": "Skipping unsupported import type form \"{argument}\".",
|
|
21
|
+
"unresolvedImportTypeQualifier": "Could not resolve import type qualifier for \"{argument}\".",
|
|
22
|
+
"unresolvedTypeQueryTarget": "Could not resolve type query target \"{target}\".",
|
|
23
|
+
"unsupportedInferredExpressionKind": "Skipping unsupported inferred expression kind \"{kind}\".",
|
|
24
|
+
"unsupportedInferredObjectComputedKey": "Skipping inferred object property with unsupported computed key \"{propertyName}\".",
|
|
25
|
+
"unsupportedInferredObjectSpread": "Skipping inferred object spread expression \"{expression}\".",
|
|
26
|
+
"unsupportedInferredObjectMemberKind": "Skipping inferred object member kind \"{kind}\".",
|
|
27
|
+
"unsupportedInferredTupleElement": "Skipping unsupported inferred tuple element kind \"{kind}\".",
|
|
28
|
+
"unsupportedTemplateLiteralSpan": "Could not derive a regex pattern for template literal type \"{type}\"; falling back to string.",
|
|
29
|
+
"unsupportedTypeElementMember": "Skipping unsupported type member kind \"{kind}\".",
|
|
30
|
+
"unsupportedUtilityType": "Skipping unsupported utility type \"{utilityType}\".",
|
|
31
|
+
"excludedEnclosingObjectDisallowedType": "Excluding enclosing object \"{enclosingObjectName}\" because property \"{propertyName}\" uses disallowed type \"{disallowedTypeName}\"."
|
|
32
|
+
}
|
|
33
|
+
}
|
|
3
34
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/tools-core",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "Shared
|
|
3
|
+
"version": "0.0.3-next.21",
|
|
4
|
+
"description": "Shared utilities and models for tooling packages",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/tools.git",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/core": "next",
|
|
18
18
|
"@twin.org/nameof": "next",
|
|
19
|
-
"
|
|
19
|
+
"@twin.org/tools-models": "0.0.3-next.21",
|
|
20
|
+
"glob": "13.0.6"
|
|
20
21
|
},
|
|
21
22
|
"main": "./dist/es/index.js",
|
|
22
23
|
"types": "./dist/types/index.d.ts",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IJsonSchema.js","sourceRoot":"","sources":["../../../src/models/IJsonSchema.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { AnySchemaObject } from \"ajv/dist/2020.js\";\n\n/**\n * Default schema type.\n */\nexport type IJsonSchema = AnySchemaObject;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenApi.js","sourceRoot":"","sources":["../../../src/models/IOpenApi.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonSchema } from \"./IJsonSchema.js\";\nimport type { IOpenApiPathMethod } from \"./IOpenApiPathMethod.js\";\nimport type { IOpenApiSecurityScheme } from \"./IOpenApiSecurityScheme.js\";\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApi {\n\t/**\n\t * The open api version.\n\t */\n\topenapi: string;\n\n\t/**\n\t * Info.\n\t */\n\tinfo: {\n\t\ttitle: string;\n\t\tversion: string;\n\t\tdescription: string;\n\t\tlicense?: {\n\t\t\tname: string;\n\t\t\turl: string;\n\t\t};\n\t};\n\n\t/**\n\t * The servers for the endpoints.\n\t */\n\tservers?: {\n\t\turl: string;\n\t}[];\n\n\t/**\n\t * Tags for the endpoints.\n\t */\n\ttags?: {\n\t\tname: string;\n\t\tdescription: string;\n\t}[];\n\n\t/**\n\t * The paths.\n\t */\n\tpaths: {\n\t\t[path: string]: {\n\t\t\t[method: string]: IOpenApiPathMethod;\n\t\t};\n\t};\n\n\t/**\n\t * The components.\n\t */\n\tcomponents?: {\n\t\tschemas?: IJsonSchema;\n\t\tsecuritySchemes?: {\n\t\t\t[name: string]: IOpenApiSecurityScheme;\n\t\t};\n\t};\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenApiExample.js","sourceRoot":"","sources":["../../../src/models/IOpenApiExample.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApiExample {\n\t/**\n\t * The summary of the example.\n\t */\n\tsummary?: string;\n\n\t/**\n\t * The value of the example.\n\t */\n\tvalue: unknown;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IOpenApiHeader.js","sourceRoot":"","sources":["../../../src/models/IOpenApiHeader.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The Open API config definition.\n */\nexport interface IOpenApiHeader {\n\t/**\n\t * The schema of the header.\n\t */\n\tschema?: {\n\t\ttype: string;\n\t};\n\n\t/**\n\t * The description of the header.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * The format of the header.\n\t */\n\tformat?: string;\n}\n"]}
|