@twin.org/ts-to-schema 0.0.1 → 0.0.2-next.10

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.
@@ -5,12 +5,12 @@ var node_url = require('node:url');
5
5
  var cliCore = require('@twin.org/cli-core');
6
6
  var promises = require('node:fs/promises');
7
7
  var core = require('@twin.org/core');
8
+ var toolsCore = require('@twin.org/tools-core');
8
9
  var tsJsonSchemaGenerator = require('ts-json-schema-generator');
9
10
 
10
11
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
12
  // Copyright 2024 IOTA Stiftung.
12
13
  // SPDX-License-Identifier: Apache-2.0.
13
- const SCHEMA_VERSION = "https://json-schema.org/draft/2020-12/schema";
14
14
  /**
15
15
  * Build the root command to be consumed by the CLI.
16
16
  * @param program The command to build on.
@@ -89,7 +89,14 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
89
89
  }
90
90
  else {
91
91
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
92
- const schemas = await generateSchemas(typeSource, type, workingDirectory);
92
+ const autoExpandTypes = config.autoExpandTypes ?? [];
93
+ const defaultExpandTypes = ["/ObjectOrArray<.*>/"];
94
+ for (const defaultType of defaultExpandTypes) {
95
+ if (!autoExpandTypes.includes(defaultType)) {
96
+ autoExpandTypes.push(defaultType);
97
+ }
98
+ }
99
+ const schemas = await generateSchemas(typeSource, type, autoExpandTypes, workingDirectory);
93
100
  if (core.Is.empty(schemas[type])) {
94
101
  throw new core.GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
95
102
  }
@@ -115,11 +122,12 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
115
122
  * Generate schemas for the models.
116
123
  * @param modelDirWildcards The filenames for all the models.
117
124
  * @param types The types of the schema objects.
125
+ * @param autoExpandTypes The types to automatically expand.
118
126
  * @param outputWorkingDir The working directory.
119
127
  * @returns Nothing.
120
128
  * @internal
121
129
  */
122
- async function generateSchemas(typeSource, type, outputWorkingDir) {
130
+ async function generateSchemas(typeSource, type, autoExpandTypes, outputWorkingDir) {
123
131
  const allSchemas = {};
124
132
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.ts-to-schema.progress.models"), typeSource, 1);
125
133
  const generator = tsJsonSchemaGenerator.createGenerator({
@@ -132,82 +140,15 @@ async function generateSchemas(typeSource, type, outputWorkingDir) {
132
140
  const schema = generator.createSchema("*");
133
141
  if (schema.definitions) {
134
142
  for (const def in schema.definitions) {
135
- const defSub = normaliseTypeName(def);
143
+ const defSub = toolsCore.JsonSchemaHelper.normaliseTypeName(def);
136
144
  allSchemas[defSub] = schema.definitions[def];
137
145
  }
138
146
  }
139
147
  const referencedSchemas = {};
140
- extractTypes(allSchemas, [type], referencedSchemas);
148
+ toolsCore.JsonSchemaHelper.extractTypes(allSchemas, [type, ...autoExpandTypes], referencedSchemas);
149
+ toolsCore.JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
141
150
  return referencedSchemas;
142
151
  }
143
- /**
144
- * Extract the required types from all the known schemas.
145
- * @param allSchemas All the known schemas.
146
- * @param requiredTypes The required types.
147
- * @param referencedSchemas The references schemas.
148
- * @internal
149
- */
150
- function extractTypes(allSchemas, requiredTypes, referencedSchemas) {
151
- for (const type of requiredTypes) {
152
- if (allSchemas[type] && !referencedSchemas[type]) {
153
- referencedSchemas[type] = allSchemas[type];
154
- extractTypesFromSchema(allSchemas, allSchemas[type], referencedSchemas);
155
- }
156
- }
157
- }
158
- /**
159
- * Extract type from properties definition.
160
- * @param allTypes All the known types.
161
- * @param schema The schema to extract from.
162
- * @param output The output types.
163
- * @internal
164
- */
165
- function extractTypesFromSchema(allTypes, schema, output) {
166
- const additionalTypes = [];
167
- if (core.Is.stringValue(schema.$ref)) {
168
- additionalTypes.push(schema.$ref.replace("#/definitions/", "").replace(/^Partial%3C(.*?)%3E/g, "$1"));
169
- }
170
- else if (core.Is.object(schema.items)) {
171
- if (core.Is.arrayValue(schema.items)) {
172
- for (const itemSchema of schema.items) {
173
- extractTypesFromSchema(allTypes, itemSchema, output);
174
- }
175
- }
176
- else {
177
- extractTypesFromSchema(allTypes, schema.items, output);
178
- }
179
- }
180
- else if (core.Is.object(schema.properties) || core.Is.object(schema.additionalProperties)) {
181
- if (core.Is.object(schema.properties)) {
182
- for (const prop in schema.properties) {
183
- const p = schema.properties[prop];
184
- if (core.Is.object(p)) {
185
- extractTypesFromSchema(allTypes, p, output);
186
- }
187
- }
188
- }
189
- if (core.Is.object(schema.additionalProperties)) {
190
- extractTypesFromSchema(allTypes, schema.additionalProperties, output);
191
- }
192
- }
193
- else if (core.Is.arrayValue(schema.anyOf)) {
194
- for (const prop of schema.anyOf) {
195
- if (core.Is.object(prop)) {
196
- extractTypesFromSchema(allTypes, prop, output);
197
- }
198
- }
199
- }
200
- else if (core.Is.arrayValue(schema.oneOf)) {
201
- for (const prop of schema.oneOf) {
202
- if (core.Is.object(prop)) {
203
- extractTypesFromSchema(allTypes, prop, output);
204
- }
205
- }
206
- }
207
- if (additionalTypes.length > 0) {
208
- extractTypes(allTypes, additionalTypes, output);
209
- }
210
- }
211
152
  /**
212
153
  * Process the schema object to ensure it has the correct properties.
213
154
  * @param schemaObject The schema object to process.
@@ -216,88 +157,15 @@ function extractTypesFromSchema(allTypes, schema, output) {
216
157
  * @returns The finalised schema object.
217
158
  */
218
159
  function finaliseSchema(schemaObject, baseUrl, type) {
219
- processArrays(schemaObject);
160
+ toolsCore.JsonSchemaHelper.processArrays(schemaObject);
220
161
  const { description, ...rest } = schemaObject;
221
162
  return {
222
- $schema: SCHEMA_VERSION,
163
+ $schema: toolsCore.JsonSchemaHelper.SCHEMA_VERSION,
223
164
  $id: `${baseUrl}${core.StringHelper.stripPrefix(type)}`,
224
165
  description,
225
166
  ...rest
226
167
  };
227
168
  }
228
- /**
229
- * Process arrays in the schema object.
230
- * @param schemaObject The schema object to process.
231
- */
232
- function processArrays(schemaObject) {
233
- if (core.Is.object(schemaObject)) {
234
- // latest specs have singular items in `items` property
235
- // and multiple items in prefixItems, so update the schema accordingly
236
- // https://www.learnjsonschema.com/2020-12/applicator/items/
237
- // https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
238
- const schemaItems = schemaObject.items;
239
- if (core.Is.array(schemaItems) || core.Is.object(schemaItems)) {
240
- schemaObject.prefixItems = core.ArrayHelper.fromObjectOrArray(schemaItems);
241
- schemaObject.items = false;
242
- }
243
- const additionalItems = schemaObject.additionalItems;
244
- if (core.Is.array(additionalItems) || core.Is.object(additionalItems)) {
245
- schemaObject.items = core.ArrayHelper.fromObjectOrArray(additionalItems)[0];
246
- delete schemaObject.additionalItems;
247
- }
248
- processSchemaDictionary(schemaObject.properties);
249
- processArrays(schemaObject.additionalProperties);
250
- processSchemaArray(schemaObject.allOf);
251
- processSchemaArray(schemaObject.anyOf);
252
- processSchemaArray(schemaObject.oneOf);
253
- }
254
- }
255
- /**
256
- * Process arrays in the schema object.
257
- * @param schemaDictionary The schema object to process.
258
- */
259
- function processSchemaDictionary(schemaDictionary) {
260
- if (core.Is.object(schemaDictionary)) {
261
- for (const item of Object.values(schemaDictionary)) {
262
- if (core.Is.object(item)) {
263
- processArrays(item);
264
- }
265
- }
266
- }
267
- }
268
- /**
269
- * Process arrays in the schema object.
270
- * @param schemaArray The schema object to process.
271
- */
272
- function processSchemaArray(schemaArray) {
273
- if (core.Is.arrayValue(schemaArray)) {
274
- for (const item of schemaArray) {
275
- if (core.Is.object(item)) {
276
- processArrays(item);
277
- }
278
- }
279
- }
280
- }
281
- /**
282
- * Cleanup TypeScript markers from the type name.
283
- * @param typeName The definition string to clean up.
284
- * @returns The cleaned up definition string.
285
- */
286
- function normaliseTypeName(typeName) {
287
- // Remove the partial markers
288
- let sTypeName = typeName.replace(/^Partial<(.*?)>/g, "$1");
289
- sTypeName = sTypeName.replace(/Partial%3CI(.*?)%3E/g, "$1");
290
- // Remove the omit markers
291
- sTypeName = sTypeName.replace(/^Omit<(.*?),.*>/g, "$1");
292
- sTypeName = sTypeName.replace(/Omit%3CI(.*?)%2C.*%3E/g, "$1");
293
- // Remove the pick markers
294
- sTypeName = sTypeName.replace(/^Pick<(.*?),.*>/g, "$1");
295
- sTypeName = sTypeName.replace(/Pick%3CI(.*?)%2C.*%3E/g, "$1");
296
- // Cleanup the generic markers
297
- sTypeName = sTypeName.replace(/</g, "%3C").replace(/>/g, "%3E");
298
- sTypeName = sTypeName.replace(/%3Cunknown%3E/g, "");
299
- return sTypeName;
300
- }
301
169
 
302
170
  // Copyright 2024 IOTA Stiftung.
303
171
  // SPDX-License-Identifier: Apache-2.0.
@@ -317,7 +185,7 @@ class CLI extends cliCore.CLIBase {
317
185
  return this.execute({
318
186
  title: "TWIN TypeScript To Schema",
319
187
  appName: "ts-to-schema",
320
- version: "0.0.1", // x-release-please-version
188
+ version: "0.0.2-next.10", // x-release-please-version
321
189
  icon: "⚙️ ",
322
190
  supportsEnvFiles: false,
323
191
  overrideOutputWidth: options?.overrideOutputWidth
@@ -2,12 +2,12 @@ import path from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { CLIDisplay, CLIUtils, CLIBase } from '@twin.org/cli-core';
4
4
  import { mkdir, rm, writeFile } from 'node:fs/promises';
5
- import { I18n, GeneralError, Is, StringHelper, ArrayHelper } from '@twin.org/core';
5
+ import { I18n, GeneralError, Is, StringHelper } from '@twin.org/core';
6
+ import { JsonSchemaHelper } from '@twin.org/tools-core';
6
7
  import { createGenerator } from 'ts-json-schema-generator';
7
8
 
8
9
  // Copyright 2024 IOTA Stiftung.
9
10
  // SPDX-License-Identifier: Apache-2.0.
10
- const SCHEMA_VERSION = "https://json-schema.org/draft/2020-12/schema";
11
11
  /**
12
12
  * Build the root command to be consumed by the CLI.
13
13
  * @param program The command to build on.
@@ -86,7 +86,14 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
86
86
  }
87
87
  else {
88
88
  CLIDisplay.task(I18n.formatMessage("commands.ts-to-schema.progress.generatingSchema"));
89
- const schemas = await generateSchemas(typeSource, type, workingDirectory);
89
+ const autoExpandTypes = config.autoExpandTypes ?? [];
90
+ const defaultExpandTypes = ["/ObjectOrArray<.*>/"];
91
+ for (const defaultType of defaultExpandTypes) {
92
+ if (!autoExpandTypes.includes(defaultType)) {
93
+ autoExpandTypes.push(defaultType);
94
+ }
95
+ }
96
+ const schemas = await generateSchemas(typeSource, type, autoExpandTypes, workingDirectory);
90
97
  if (Is.empty(schemas[type])) {
91
98
  throw new GeneralError("commands", "commands.ts-to-schema.schemaNotFound", { type });
92
99
  }
@@ -112,11 +119,12 @@ async function tsToSchema(config, outputFolder, workingDirectory) {
112
119
  * Generate schemas for the models.
113
120
  * @param modelDirWildcards The filenames for all the models.
114
121
  * @param types The types of the schema objects.
122
+ * @param autoExpandTypes The types to automatically expand.
115
123
  * @param outputWorkingDir The working directory.
116
124
  * @returns Nothing.
117
125
  * @internal
118
126
  */
119
- async function generateSchemas(typeSource, type, outputWorkingDir) {
127
+ async function generateSchemas(typeSource, type, autoExpandTypes, outputWorkingDir) {
120
128
  const allSchemas = {};
121
129
  CLIDisplay.value(I18n.formatMessage("commands.ts-to-schema.progress.models"), typeSource, 1);
122
130
  const generator = createGenerator({
@@ -129,82 +137,15 @@ async function generateSchemas(typeSource, type, outputWorkingDir) {
129
137
  const schema = generator.createSchema("*");
130
138
  if (schema.definitions) {
131
139
  for (const def in schema.definitions) {
132
- const defSub = normaliseTypeName(def);
140
+ const defSub = JsonSchemaHelper.normaliseTypeName(def);
133
141
  allSchemas[defSub] = schema.definitions[def];
134
142
  }
135
143
  }
136
144
  const referencedSchemas = {};
137
- extractTypes(allSchemas, [type], referencedSchemas);
145
+ JsonSchemaHelper.extractTypes(allSchemas, [type, ...autoExpandTypes], referencedSchemas);
146
+ JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
138
147
  return referencedSchemas;
139
148
  }
140
- /**
141
- * Extract the required types from all the known schemas.
142
- * @param allSchemas All the known schemas.
143
- * @param requiredTypes The required types.
144
- * @param referencedSchemas The references schemas.
145
- * @internal
146
- */
147
- function extractTypes(allSchemas, requiredTypes, referencedSchemas) {
148
- for (const type of requiredTypes) {
149
- if (allSchemas[type] && !referencedSchemas[type]) {
150
- referencedSchemas[type] = allSchemas[type];
151
- extractTypesFromSchema(allSchemas, allSchemas[type], referencedSchemas);
152
- }
153
- }
154
- }
155
- /**
156
- * Extract type from properties definition.
157
- * @param allTypes All the known types.
158
- * @param schema The schema to extract from.
159
- * @param output The output types.
160
- * @internal
161
- */
162
- function extractTypesFromSchema(allTypes, schema, output) {
163
- const additionalTypes = [];
164
- if (Is.stringValue(schema.$ref)) {
165
- additionalTypes.push(schema.$ref.replace("#/definitions/", "").replace(/^Partial%3C(.*?)%3E/g, "$1"));
166
- }
167
- else if (Is.object(schema.items)) {
168
- if (Is.arrayValue(schema.items)) {
169
- for (const itemSchema of schema.items) {
170
- extractTypesFromSchema(allTypes, itemSchema, output);
171
- }
172
- }
173
- else {
174
- extractTypesFromSchema(allTypes, schema.items, output);
175
- }
176
- }
177
- else if (Is.object(schema.properties) || Is.object(schema.additionalProperties)) {
178
- if (Is.object(schema.properties)) {
179
- for (const prop in schema.properties) {
180
- const p = schema.properties[prop];
181
- if (Is.object(p)) {
182
- extractTypesFromSchema(allTypes, p, output);
183
- }
184
- }
185
- }
186
- if (Is.object(schema.additionalProperties)) {
187
- extractTypesFromSchema(allTypes, schema.additionalProperties, output);
188
- }
189
- }
190
- else if (Is.arrayValue(schema.anyOf)) {
191
- for (const prop of schema.anyOf) {
192
- if (Is.object(prop)) {
193
- extractTypesFromSchema(allTypes, prop, output);
194
- }
195
- }
196
- }
197
- else if (Is.arrayValue(schema.oneOf)) {
198
- for (const prop of schema.oneOf) {
199
- if (Is.object(prop)) {
200
- extractTypesFromSchema(allTypes, prop, output);
201
- }
202
- }
203
- }
204
- if (additionalTypes.length > 0) {
205
- extractTypes(allTypes, additionalTypes, output);
206
- }
207
- }
208
149
  /**
209
150
  * Process the schema object to ensure it has the correct properties.
210
151
  * @param schemaObject The schema object to process.
@@ -213,88 +154,15 @@ function extractTypesFromSchema(allTypes, schema, output) {
213
154
  * @returns The finalised schema object.
214
155
  */
215
156
  function finaliseSchema(schemaObject, baseUrl, type) {
216
- processArrays(schemaObject);
157
+ JsonSchemaHelper.processArrays(schemaObject);
217
158
  const { description, ...rest } = schemaObject;
218
159
  return {
219
- $schema: SCHEMA_VERSION,
160
+ $schema: JsonSchemaHelper.SCHEMA_VERSION,
220
161
  $id: `${baseUrl}${StringHelper.stripPrefix(type)}`,
221
162
  description,
222
163
  ...rest
223
164
  };
224
165
  }
225
- /**
226
- * Process arrays in the schema object.
227
- * @param schemaObject The schema object to process.
228
- */
229
- function processArrays(schemaObject) {
230
- if (Is.object(schemaObject)) {
231
- // latest specs have singular items in `items` property
232
- // and multiple items in prefixItems, so update the schema accordingly
233
- // https://www.learnjsonschema.com/2020-12/applicator/items/
234
- // https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
235
- const schemaItems = schemaObject.items;
236
- if (Is.array(schemaItems) || Is.object(schemaItems)) {
237
- schemaObject.prefixItems = ArrayHelper.fromObjectOrArray(schemaItems);
238
- schemaObject.items = false;
239
- }
240
- const additionalItems = schemaObject.additionalItems;
241
- if (Is.array(additionalItems) || Is.object(additionalItems)) {
242
- schemaObject.items = ArrayHelper.fromObjectOrArray(additionalItems)[0];
243
- delete schemaObject.additionalItems;
244
- }
245
- processSchemaDictionary(schemaObject.properties);
246
- processArrays(schemaObject.additionalProperties);
247
- processSchemaArray(schemaObject.allOf);
248
- processSchemaArray(schemaObject.anyOf);
249
- processSchemaArray(schemaObject.oneOf);
250
- }
251
- }
252
- /**
253
- * Process arrays in the schema object.
254
- * @param schemaDictionary The schema object to process.
255
- */
256
- function processSchemaDictionary(schemaDictionary) {
257
- if (Is.object(schemaDictionary)) {
258
- for (const item of Object.values(schemaDictionary)) {
259
- if (Is.object(item)) {
260
- processArrays(item);
261
- }
262
- }
263
- }
264
- }
265
- /**
266
- * Process arrays in the schema object.
267
- * @param schemaArray The schema object to process.
268
- */
269
- function processSchemaArray(schemaArray) {
270
- if (Is.arrayValue(schemaArray)) {
271
- for (const item of schemaArray) {
272
- if (Is.object(item)) {
273
- processArrays(item);
274
- }
275
- }
276
- }
277
- }
278
- /**
279
- * Cleanup TypeScript markers from the type name.
280
- * @param typeName The definition string to clean up.
281
- * @returns The cleaned up definition string.
282
- */
283
- function normaliseTypeName(typeName) {
284
- // Remove the partial markers
285
- let sTypeName = typeName.replace(/^Partial<(.*?)>/g, "$1");
286
- sTypeName = sTypeName.replace(/Partial%3CI(.*?)%3E/g, "$1");
287
- // Remove the omit markers
288
- sTypeName = sTypeName.replace(/^Omit<(.*?),.*>/g, "$1");
289
- sTypeName = sTypeName.replace(/Omit%3CI(.*?)%2C.*%3E/g, "$1");
290
- // Remove the pick markers
291
- sTypeName = sTypeName.replace(/^Pick<(.*?),.*>/g, "$1");
292
- sTypeName = sTypeName.replace(/Pick%3CI(.*?)%2C.*%3E/g, "$1");
293
- // Cleanup the generic markers
294
- sTypeName = sTypeName.replace(/</g, "%3C").replace(/>/g, "%3E");
295
- sTypeName = sTypeName.replace(/%3Cunknown%3E/g, "");
296
- return sTypeName;
297
- }
298
166
 
299
167
  // Copyright 2024 IOTA Stiftung.
300
168
  // SPDX-License-Identifier: Apache-2.0.
@@ -314,7 +182,7 @@ class CLI extends CLIBase {
314
182
  return this.execute({
315
183
  title: "TWIN TypeScript To Schema",
316
184
  appName: "ts-to-schema",
317
- version: "0.0.1", // x-release-please-version
185
+ version: "0.0.2-next.10", // x-release-please-version
318
186
  icon: "⚙️ ",
319
187
  supportsEnvFiles: false,
320
188
  overrideOutputWidth: options?.overrideOutputWidth
@@ -6,7 +6,6 @@
6
6
  "optionInvalidHex": "The \"{option}\" does not appear to be hex. \"{value}\"",
7
7
  "optionInvalidBase64": "The \"{option}\" does not appear to be base64. \"{value}\"",
8
8
  "optionInvalidHexBase64": "The \"{option}\" does not appear to be hex or base64. \"{value}\"",
9
- "optionInvalidBech32": "The \"{option}\" does not appear to be bech32. \"{value}\"",
10
9
  "optionMinValue": "The \"{option}\" option must be greater than or equal to {minValue}, it is {value}.",
11
10
  "optionMaxValue": "The \"{option}\" option must be less than or equal to {maxValue}, it is {value}."
12
11
  },
@@ -53,9 +52,7 @@
53
52
  "beUrn": "{fieldName} must be a correctly formatted urn",
54
53
  "beUrl": "{fieldName} must be a correctly formatted url",
55
54
  "beJSON": "{fieldName} must be correctly formatted JSON",
56
- "beEmail": "{fieldName} must be a correctly formatted e-mail address",
57
- "failed": "Validation failed",
58
- "failedObject": "Validation of \"{objectName}\" failed"
55
+ "beEmail": "{fieldName} must be a correctly formatted e-mail address"
59
56
  },
60
57
  "guard": {
61
58
  "undefined": "Property \"{property}\" must be defined, it is \"{value}\"",
@@ -86,11 +83,7 @@
86
83
  "function": "Property \"{property}\" must be a function, it is \"{value}\"",
87
84
  "urn": "Property \"{property}\" must be a Urn formatted string, it is \"{value}\"",
88
85
  "url": "Property \"{property}\" must be a Url formatted string, it is \"{value}\"",
89
- "email": "Property \"{property}\" must be string in e-mail format, it is \"{value}\"",
90
- "length32Multiple": "Property \"{property}\" should be a multiple of 32, it is {value}",
91
- "lengthEntropy": "Property \"{property}\" should be a multiple of 4, >=16 and <= 32, it is {value}",
92
- "length3Multiple": "Property \"{property}\" should be a multiple of 3, it is {value}",
93
- "greaterThan0": "Property \"{property}\" must be greater than zero, it is {value}"
86
+ "email": "Property \"{property}\" must be string in e-mail format, it is \"{value}\""
94
87
  },
95
88
  "objectHelper": {
96
89
  "failedBytesToJSON": "Failed converting bytes to JSON",
@@ -106,7 +99,7 @@
106
99
  "noGet": "The requested {typeName} \"{name}\" does not exist in the factory"
107
100
  },
108
101
  "bitString": {
109
- "outOfRange": "The index should be >= 0 and less than the length of the bit string"
102
+ "outOfRange": "The index should be >= 0 and less than the length of the bit string, the index is \"{index}\" and the number of bit is \"{numberBits}\""
110
103
  },
111
104
  "base32": {
112
105
  "invalidCharacter": "Data contains a character \"{invalidCharacter}\" which is not in the charset"
@@ -119,64 +112,11 @@
119
112
  },
120
113
  "jsonHelper": {
121
114
  "failedPatch": "Failed to patch the JSON object, patch index \"{index}\" failed"
122
- },
123
- "bip39": {
124
- "missingMnemonicWord": "The mnemonic contains a word not in the wordlist, \"{value}\"",
125
- "checksumMismatch": "The checksum does not match \"{newChecksum}\" != \"{checksumBits}\""
126
- },
127
- "ed25519": {
128
- "privateKeyLength": "The private key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\"",
129
- "publicKeyLength": "The public key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\""
130
- },
131
- "secp256k1": {
132
- "privateKeyLength": "The private key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\"",
133
- "publicKeyLength": "The public key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\""
134
- },
135
- "x25519": {
136
- "invalidPublicKey": "Invalid Ed25519 Public Key"
137
- },
138
- "blake2b": {
139
- "outputLength64": "The output length should be between 1 and 64, it is \"{outputLength}\"",
140
- "keyLength64": "The key length should be between 1 and 64, it is \"{keyLength}\""
141
- },
142
- "sha512": {
143
- "bitSize": "Only 224, 256, 384 or 512 bits are supported, it is \"{bitSize}\""
144
- },
145
- "sha256": {
146
- "bitSize": "Only 224 or 256 bits are supported, it is \"{bitSize}\""
147
- },
148
- "sha3": {
149
- "bitSize": "Only 224, 256, 384 or 512 bits are supported, it is \"{bitSize}\""
150
- },
151
- "hmacSha256": {
152
- "bitSize": "Only 224 or 256 bits are supported, it is \"{bitSize}\""
153
- },
154
- "hmacSha512": {
155
- "bitSize": "Only 224, 256, 384 or 512 bits are supported, it is \"{bitSize}\""
156
- },
157
- "bech32": {
158
- "decodeFailed": "The address contains decoding failed for address \"{bech32}\"",
159
- "invalidChecksum": "The address contains an invalid checksum in address, \"{bech32}\"",
160
- "separatorMisused": "The separator character '1' should only be used between hrp and data, \"{bech32}\"",
161
- "lowerUpper": "The address my use either lowercase or uppercase, \"{bech32}\"",
162
- "dataTooShort": "The address does not contain enough data to decode, \"{bech32}\""
163
- },
164
- "pbkdf2": {
165
- "keyTooLong": "The requested key length \"{keyLength}\" is too long, based on the \"{macLength}\""
166
- },
167
- "chaCha20Poly1305": {
168
- "noAadWithData": "You can not set the aad when there is already data",
169
- "noAuthTag": "Can not finalise when the auth tag is not set",
170
- "authenticationFailed": "The data could not be authenticated",
171
- "authTagDecrypting": "Can not get the auth tag when decrypting",
172
- "authTagEncrypting": "Can not set the auth tag when encrypting",
173
- "noAuthTagSet": "The auth tag has not been set"
174
- },
175
- "bip44": {
176
- "unsupportedKeyType": "The key type \"{keyType}\" is not supported"
177
- },
178
- "slip0010": {
179
- "invalidSeed": "The seed is invalid \"{seed}\""
115
+ }
116
+ },
117
+ "warn": {
118
+ "common": {
119
+ "devOnlyTool": "This tool is intended to be used for development purposes, it is not recommended for use in production scenarios."
180
120
  }
181
121
  },
182
122
  "cli": {
@@ -231,7 +171,8 @@
231
171
  "alreadyExistsError": "Already Exists",
232
172
  "notImplementedError": "Not Implemented",
233
173
  "validationError": "Validation",
234
- "unprocessableError": "Unprocessable"
174
+ "unprocessableError": "Unprocessable",
175
+ "unauthorizedError": "Unauthorized"
235
176
  },
236
177
  "validation": {
237
178
  "defaultFieldName": "The field"
@@ -1,4 +1,4 @@
1
- import type { IJsonSchema } from "./IJsonSchema";
1
+ import type { IJsonSchema } from "@twin.org/tools-core";
2
2
  /**
3
3
  * Configuration for the tool.
4
4
  */
@@ -12,7 +12,7 @@ export interface ITsToSchemaConfig {
12
12
  */
13
13
  types: string[];
14
14
  /**
15
- * External type references
15
+ * External type references.
16
16
  */
17
17
  externalReferences?: {
18
18
  [id: string]: string;
@@ -23,4 +23,8 @@ export interface ITsToSchemaConfig {
23
23
  overrides?: {
24
24
  [id: string]: IJsonSchema;
25
25
  };
26
+ /**
27
+ * The types to automatically expand inline in type definitions, reg ex string matches.
28
+ */
29
+ autoExpandTypes?: string[];
26
30
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,156 @@
1
1
  # @twin.org/ts-to-schema - Changelog
2
2
 
3
+ ## [0.0.2-next.10](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.9...ts-to-schema-v0.0.2-next.10) (2025-10-09)
4
+
5
+
6
+ ### Features
7
+
8
+ * add validate-locales ([97bb11f](https://github.com/twinfoundation/tools/commit/97bb11fd9e6ed400e7fa69671075ba78f36ca6e6))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/tools-core bumped from 0.0.2-next.9 to 0.0.2-next.10
16
+
17
+ ## [0.0.2-next.9](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.8...ts-to-schema-v0.0.2-next.9) (2025-09-23)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **ts-to-schema:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/tools-core bumped from 0.0.2-next.8 to 0.0.2-next.9
30
+
31
+ ## [0.0.2-next.8](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.7...ts-to-schema-v0.0.2-next.8) (2025-09-05)
32
+
33
+
34
+ ### Miscellaneous Chores
35
+
36
+ * **ts-to-schema:** Synchronize repo versions
37
+
38
+
39
+ ### Dependencies
40
+
41
+ * The following workspace dependencies were updated
42
+ * dependencies
43
+ * @twin.org/tools-core bumped from 0.0.2-next.7 to 0.0.2-next.8
44
+
45
+ ## [0.0.2-next.7](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.6...ts-to-schema-v0.0.2-next.7) (2025-08-29)
46
+
47
+
48
+ ### Features
49
+
50
+ * eslint migration to flat config ([25acfcf](https://github.com/twinfoundation/tools/commit/25acfcf4c4e0c496fffeaf67659fe171bc15199a))
51
+
52
+
53
+ ### Dependencies
54
+
55
+ * The following workspace dependencies were updated
56
+ * dependencies
57
+ * @twin.org/tools-core bumped from 0.0.2-next.6 to 0.0.2-next.7
58
+
59
+ ## [0.0.2-next.6](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.5...ts-to-schema-v0.0.2-next.6) (2025-08-21)
60
+
61
+
62
+ ### Miscellaneous Chores
63
+
64
+ * **ts-to-schema:** Synchronize repo versions
65
+
66
+
67
+ ### Dependencies
68
+
69
+ * The following workspace dependencies were updated
70
+ * dependencies
71
+ * @twin.org/tools-core bumped from 0.0.2-next.5 to 0.0.2-next.6
72
+
73
+ ## [0.0.2-next.5](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.4...ts-to-schema-v0.0.2-next.5) (2025-08-19)
74
+
75
+
76
+ ### Features
77
+
78
+ * correctly handle auto expand types ([57fce0f](https://github.com/twinfoundation/tools/commit/57fce0f9ec4a0876665d70adc6e885f6feb3caf7))
79
+
80
+
81
+ ### Dependencies
82
+
83
+ * The following workspace dependencies were updated
84
+ * dependencies
85
+ * @twin.org/tools-core bumped from 0.0.2-next.4 to 0.0.2-next.5
86
+
87
+ ## [0.0.2-next.4](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.3...ts-to-schema-v0.0.2-next.4) (2025-08-19)
88
+
89
+
90
+ ### Miscellaneous Chores
91
+
92
+ * **ts-to-schema:** Synchronize repo versions
93
+
94
+
95
+ ### Dependencies
96
+
97
+ * The following workspace dependencies were updated
98
+ * dependencies
99
+ * @twin.org/tools-core bumped from 0.0.2-next.3 to 0.0.2-next.4
100
+
101
+ ## [0.0.2-next.3](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.2...ts-to-schema-v0.0.2-next.3) (2025-08-05)
102
+
103
+
104
+ ### Miscellaneous Chores
105
+
106
+ * **ts-to-schema:** Synchronize repo versions
107
+
108
+
109
+ ### Dependencies
110
+
111
+ * The following workspace dependencies were updated
112
+ * dependencies
113
+ * @twin.org/tools-core bumped from 0.0.2-next.2 to 0.0.2-next.3
114
+
115
+ ## [0.0.2-next.2](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.1...ts-to-schema-v0.0.2-next.2) (2025-07-17)
116
+
117
+
118
+ ### Features
119
+
120
+ * improve auto expand types ([6181d1d](https://github.com/twinfoundation/tools/commit/6181d1daded1f91323195cf7efbc2f1881f38b41))
121
+
122
+
123
+ ### Dependencies
124
+
125
+ * The following workspace dependencies were updated
126
+ * dependencies
127
+ * @twin.org/tools-core bumped from 0.0.2-next.1 to 0.0.2-next.2
128
+
129
+ ## [0.0.2-next.1](https://github.com/twinfoundation/tools/compare/ts-to-schema-v0.0.2-next.0...ts-to-schema-v0.0.2-next.1) (2025-07-14)
130
+
131
+
132
+ ### Features
133
+
134
+ * add support for auto expand types ([dd1e10a](https://github.com/twinfoundation/tools/commit/dd1e10a5b2fea6f80890ff6f3971f48e239cb4c1))
135
+ * add ts-to-schema overrides ([3c54504](https://github.com/twinfoundation/tools/commit/3c5450468eb998204a75576b7791a7ca4027da62))
136
+ * generate schemas as individual entities ([9f372ab](https://github.com/twinfoundation/tools/commit/9f372abdfc27aba93b303c7b214991919c0c18c3))
137
+ * improve schema type name normalisation ([1a18b26](https://github.com/twinfoundation/tools/commit/1a18b267d87e9179bda01b396b256c450ae2889e))
138
+ * move package to framework repo ([4490bda](https://github.com/twinfoundation/tools/commit/4490bda472d4dc8ddfe931e2fce81f3411de9ab3))
139
+ * use most recent JSON schema specs ([4598cbf](https://github.com/twinfoundation/tools/commit/4598cbf29f7b82dba4a9f3b19f81dfe66f5a6060))
140
+ * use shared store mechanism ([#31](https://github.com/twinfoundation/tools/issues/31)) ([d9fe68b](https://github.com/twinfoundation/tools/commit/d9fe68b903d1268c7cb3c64772df5cb78fd63667))
141
+
142
+
143
+ ### Bug Fixes
144
+
145
+ * remove debugging ([4def3d1](https://github.com/twinfoundation/tools/commit/4def3d1ef6a41a3b3358f864214e6a7ec3f9c638))
146
+
147
+
148
+ ### Dependencies
149
+
150
+ * The following workspace dependencies were updated
151
+ * dependencies
152
+ * @twin.org/tools-core bumped from 0.0.2-next.0 to 0.0.2-next.1
153
+
3
154
  ## 0.0.1 (2025-07-03)
4
155
 
5
156
 
@@ -24,7 +24,7 @@ The source files to generate the types from.
24
24
 
25
25
  > `optional` **externalReferences**: `object`
26
26
 
27
- External type references
27
+ External type references.
28
28
 
29
29
  #### Index Signature
30
30
 
@@ -41,3 +41,11 @@ Override for specific types, to be used when the type cannot be generated automa
41
41
  #### Index Signature
42
42
 
43
43
  \[`id`: `string`\]: `AnySchemaObject`
44
+
45
+ ***
46
+
47
+ ### autoExpandTypes?
48
+
49
+ > `optional` **autoExpandTypes**: `string`[]
50
+
51
+ The types to automatically expand inline in type definitions, reg ex string matches.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/ts-to-schema",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-next.10",
4
4
  "description": "Tool to convert TypeScript definitions to JSON schemas",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,12 +14,12 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/cli-core": "^0.0.1",
18
- "@twin.org/core": "^0.0.1",
19
- "@twin.org/nameof": "^0.0.1",
20
- "ajv": "8.17.1",
21
- "commander": "14.0.0",
22
- "glob": "11.0.2",
17
+ "@twin.org/cli-core": "next",
18
+ "@twin.org/core": "next",
19
+ "@twin.org/nameof": "next",
20
+ "@twin.org/tools-core": "0.0.2-next.10",
21
+ "commander": "14.0.1",
22
+ "glob": "11.0.3",
23
23
  "ts-json-schema-generator": "2.4.0"
24
24
  },
25
25
  "main": "./dist/cjs/index.cjs",
@@ -43,5 +43,17 @@
43
43
  ],
44
44
  "bin": {
45
45
  "ts-to-schema": "bin/index.js"
46
- }
46
+ },
47
+ "keywords": [
48
+ "twin",
49
+ "trade",
50
+ "iota",
51
+ "framework",
52
+ "blockchain",
53
+ "tools"
54
+ ],
55
+ "bugs": {
56
+ "url": "git+https://github.com/twinfoundation/tools/issues"
57
+ },
58
+ "homepage": "https://twindev.org"
47
59
  }
@@ -1,5 +0,0 @@
1
- import type { AnySchemaObject } from "ajv/dist/2020.js";
2
- /**
3
- * Default schema type.
4
- */
5
- export type IJsonSchema = AnySchemaObject;