dtsgenerator 3.19.2 → 4.0.0

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/.husky/pre-commit CHANGED
@@ -1,4 +1 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
1
  npx lint-staged
package/.nycrc CHANGED
@@ -4,10 +4,10 @@
4
4
  "check-coverage": true,
5
5
  "exclude": [
6
6
  "**/*.js",
7
+ "**/*.cjs",
7
8
  "coverage/**",
8
9
  "node_modules/**",
9
10
  "**/*.d.ts",
10
11
  "**/*_test.ts"
11
12
  ]
12
13
  }
13
-
package/README.md CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  TypeScript d.ts file generator from JSON Schema file or OpenAPI(Swagger) spec file.
4
4
 
5
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/horiuchi/dtsgenerator)
5
6
  [![nodejs version](https://img.shields.io/node/v/dtsgenerator.svg)](#)
6
7
  [![npm version](https://badge.fury.io/js/dtsgenerator.svg)](https://www.npmjs.com/package/dtsgenerator)
7
8
  [![Build Status](https://github.com/horiuchi/dtsgenerator/actions/workflows/workflow-ci.yaml/badge.svg)](https://github.com/horiuchi/dtsgenerator/actions/workflows/workflow-ci.yaml)
8
9
  [![Coverage Status](https://coveralls.io/repos/github/horiuchi/dtsgenerator/badge.svg?branch=master)](https://coveralls.io/github/horiuchi/dtsgenerator?branch=master)
9
10
  [![npm download count](https://img.shields.io/npm/dt/dtsgenerator.svg)](https://www.npmjs.com/package/dtsgenerator)
10
- [![Stake to support us](https://badge.devprotocol.xyz/0x68c824db5A1634940BB838468Ff2aee2bDa5794B/descriptive)](https://stakes.social/0x68c824db5A1634940BB838468Ff2aee2bDa5794B)
11
+ <!-- [![Stake to support us](https://badge.devprotocol.xyz/0x68c824db5A1634940BB838468Ff2aee2bDa5794B/descriptive)](https://stakes.social/0x68c824db5A1634940BB838468Ff2aee2bDa5794B) -->
11
12
  [![MIT license](https://img.shields.io/npm/l/dtsgenerator.svg)](#)
12
13
 
13
14
  ## Table of Contents
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clear = exports.initialize = exports.CommandOptions = exports.defaultConfigFile = void 0;
3
+ exports.CommandOptions = exports.defaultConfigFile = void 0;
4
+ exports.initialize = initialize;
5
+ exports.clear = clear;
4
6
  const tslib_1 = require("tslib");
5
7
  const commander = tslib_1.__importStar(require("commander"));
6
8
  exports.defaultConfigFile = 'dtsgen.json';
@@ -17,7 +19,6 @@ exports.default = opts;
17
19
  function initialize(argv) {
18
20
  return parse(opts, argv);
19
21
  }
20
- exports.initialize = initialize;
21
22
  function clear() {
22
23
  opts.configFile = undefined;
23
24
  opts.files = [];
@@ -28,7 +29,6 @@ function clear() {
28
29
  opts.info = undefined;
29
30
  opts.outputAST = undefined;
30
31
  }
31
- exports.clear = clear;
32
32
  function parse(options, argv) {
33
33
  const program = new commander.Command();
34
34
  function collectUrl(val, memo) {
@@ -47,6 +47,7 @@ function parse(options, argv) {
47
47
  .option('-t, --target <version>', "Specify ECMAScript target version: 'ES3', 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT' (default).")
48
48
  .option('--info', 'for developer mode. output loaded config and plugin details only.')
49
49
  .option('--output-ast', 'output TypeScript AST instead of d.ts file.')
50
+ .allowExcessArguments(true)
50
51
  .addHelpText('afterAll', `
51
52
  Examples:
52
53
  $ dtsgen --help
@@ -1,6 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addOptionalInformation = exports.addComment = exports.buildTypeReferenceNode = exports.buildTupleTypeNode = exports.buildIntersectionTypeNode = exports.buildUnionTypeNode = exports.buildFreeFormObjectTypeLiteralNode = exports.buildTypeLiteralNode = exports.buildIndexSignatureNode = exports.buildPropertySignature = exports.buildTypeAliasNode = exports.buildInterfaceNode = exports.buildNamespaceNode = exports.buildBooleanLiteralTypeNode = exports.buildNumericLiteralTypeNode = exports.buildStringLiteralTypeNode = exports.buildNullKeyword = exports.buildSimpleArrayNode = exports.buildStringKeyword = exports.buildVoidKeyword = exports.buildUnknownKeyword = exports.buildNeverKeyword = exports.buildAnyKeyword = exports.buildKeyword = void 0;
3
+ exports.buildKeyword = buildKeyword;
4
+ exports.buildAnyKeyword = buildAnyKeyword;
5
+ exports.buildNeverKeyword = buildNeverKeyword;
6
+ exports.buildUnknownKeyword = buildUnknownKeyword;
7
+ exports.buildVoidKeyword = buildVoidKeyword;
8
+ exports.buildStringKeyword = buildStringKeyword;
9
+ exports.buildSimpleArrayNode = buildSimpleArrayNode;
10
+ exports.buildNullKeyword = buildNullKeyword;
11
+ exports.buildStringLiteralTypeNode = buildStringLiteralTypeNode;
12
+ exports.buildNumericLiteralTypeNode = buildNumericLiteralTypeNode;
13
+ exports.buildBooleanLiteralTypeNode = buildBooleanLiteralTypeNode;
14
+ exports.buildNamespaceNode = buildNamespaceNode;
15
+ exports.buildInterfaceNode = buildInterfaceNode;
16
+ exports.buildTypeAliasNode = buildTypeAliasNode;
17
+ exports.buildPropertySignature = buildPropertySignature;
18
+ exports.buildIndexSignatureNode = buildIndexSignatureNode;
19
+ exports.buildTypeLiteralNode = buildTypeLiteralNode;
20
+ exports.buildFreeFormObjectTypeLiteralNode = buildFreeFormObjectTypeLiteralNode;
21
+ exports.buildUnionTypeNode = buildUnionTypeNode;
22
+ exports.buildIntersectionTypeNode = buildIntersectionTypeNode;
23
+ exports.buildTupleTypeNode = buildTupleTypeNode;
24
+ exports.buildTypeReferenceNode = buildTypeReferenceNode;
25
+ exports.addComment = addComment;
26
+ exports.addOptionalInformation = addOptionalInformation;
4
27
  const tslib_1 = require("tslib");
5
28
  const ts = tslib_1.__importStar(require("typescript"));
6
29
  const config_1 = tslib_1.__importDefault(require("./config"));
@@ -19,50 +42,39 @@ function buildPropertyNameIdentifier(name) {
19
42
  function buildKeyword(kind) {
20
43
  return ts.factory.createKeywordTypeNode(kind);
21
44
  }
22
- exports.buildKeyword = buildKeyword;
23
45
  function buildAnyKeyword() {
24
46
  return buildKeyword(ts.SyntaxKind.AnyKeyword);
25
47
  }
26
- exports.buildAnyKeyword = buildAnyKeyword;
27
48
  function buildNeverKeyword() {
28
49
  return buildKeyword(ts.SyntaxKind.NeverKeyword);
29
50
  }
30
- exports.buildNeverKeyword = buildNeverKeyword;
31
51
  function buildUnknownKeyword() {
32
52
  return buildKeyword(ts.SyntaxKind.UnknownKeyword);
33
53
  }
34
- exports.buildUnknownKeyword = buildUnknownKeyword;
35
54
  function buildVoidKeyword() {
36
55
  return buildKeyword(ts.SyntaxKind.VoidKeyword);
37
56
  }
38
- exports.buildVoidKeyword = buildVoidKeyword;
39
57
  function buildStringKeyword() {
40
58
  return buildKeyword(ts.SyntaxKind.StringKeyword);
41
59
  }
42
- exports.buildStringKeyword = buildStringKeyword;
43
60
  function buildSimpleArrayNode(element) {
44
61
  return ts.factory.createArrayTypeNode(element);
45
62
  }
46
- exports.buildSimpleArrayNode = buildSimpleArrayNode;
47
63
  function buildNullKeyword() {
48
64
  return ts.factory.createLiteralTypeNode(ts.factory.createToken(ts.SyntaxKind.NullKeyword));
49
65
  }
50
- exports.buildNullKeyword = buildNullKeyword;
51
66
  function buildStringLiteralTypeNode(s) {
52
67
  return ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(s));
53
68
  }
54
- exports.buildStringLiteralTypeNode = buildStringLiteralTypeNode;
55
69
  function buildNumericLiteralTypeNode(n) {
56
70
  if (!isNaN(parseFloat(n)) && parseFloat(n) < 0) {
57
71
  return ts.factory.createLiteralTypeNode(ts.factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, ts.factory.createNumericLiteral(Math.abs(parseFloat(n)))));
58
72
  }
59
73
  return ts.factory.createLiteralTypeNode(ts.factory.createNumericLiteral(n));
60
74
  }
61
- exports.buildNumericLiteralTypeNode = buildNumericLiteralTypeNode;
62
75
  function buildBooleanLiteralTypeNode(b) {
63
76
  return ts.factory.createLiteralTypeNode(b ? ts.factory.createTrue() : ts.factory.createFalse());
64
77
  }
65
- exports.buildBooleanLiteralTypeNode = buildBooleanLiteralTypeNode;
66
78
  function buildNamespaceNode(name, statements, root) {
67
79
  const modifiers = root
68
80
  ? [ts.factory.createModifier(ts.SyntaxKind.DeclareKeyword)]
@@ -71,7 +83,6 @@ function buildNamespaceNode(name, statements, root) {
71
83
  ts.NodeFlags.ExportContext |
72
84
  ts.NodeFlags.ContextFlags);
73
85
  }
74
- exports.buildNamespaceNode = buildNamespaceNode;
75
86
  function buildInterfaceNode(id, members, root) {
76
87
  const name = getLastTypeName(id);
77
88
  const modifiers = root
@@ -79,7 +90,6 @@ function buildInterfaceNode(id, members, root) {
79
90
  : [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)];
80
91
  return ts.factory.createInterfaceDeclaration(modifiers, buildTypeNameIdentifier(name), undefined, undefined, members);
81
92
  }
82
- exports.buildInterfaceNode = buildInterfaceNode;
83
93
  function buildTypeAliasNode(id, type, root) {
84
94
  const name = getLastTypeName(id);
85
95
  const modifiers = root
@@ -87,7 +97,6 @@ function buildTypeAliasNode(id, type, root) {
87
97
  : [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)];
88
98
  return ts.factory.createTypeAliasDeclaration(modifiers, buildTypeNameIdentifier(name), undefined, type);
89
99
  }
90
- exports.buildTypeAliasNode = buildTypeAliasNode;
91
100
  function buildPropertySignature(_schema, propertyName, valueType, required, isPattern) {
92
101
  const modifiers = undefined;
93
102
  const questionToken = !(required === null || required === void 0 ? void 0 : required.includes(propertyName))
@@ -100,23 +109,19 @@ function buildPropertySignature(_schema, propertyName, valueType, required, isPa
100
109
  }
101
110
  return ts.factory.createPropertySignature(modifiers, buildPropertyNameIdentifier(propertyName), questionToken, valueType);
102
111
  }
103
- exports.buildPropertySignature = buildPropertySignature;
104
112
  function buildIndexSignatureNode(name, indexType, valueType) {
105
113
  return ts.factory.createIndexSignature(undefined, [
106
114
  ts.factory.createParameterDeclaration(undefined, undefined, buildTypeNameIdentifier(name), undefined, indexType, undefined),
107
115
  ], valueType);
108
116
  }
109
- exports.buildIndexSignatureNode = buildIndexSignatureNode;
110
117
  function buildTypeLiteralNode(elements) {
111
118
  return ts.factory.createTypeLiteralNode(elements);
112
119
  }
113
- exports.buildTypeLiteralNode = buildTypeLiteralNode;
114
120
  function buildFreeFormObjectTypeLiteralNode() {
115
121
  return ts.factory.createTypeLiteralNode([
116
122
  buildIndexSignatureNode('key', buildStringKeyword(), buildAnyKeyword()),
117
123
  ]);
118
124
  }
119
- exports.buildFreeFormObjectTypeLiteralNode = buildFreeFormObjectTypeLiteralNode;
120
125
  function buildUnionTypeNode(types, builder, terminate) {
121
126
  const node = ts.factory.createUnionTypeNode(types.map(builder));
122
127
  if (terminate) {
@@ -124,7 +129,6 @@ function buildUnionTypeNode(types, builder, terminate) {
124
129
  }
125
130
  return ts.factory.createParenthesizedType(node);
126
131
  }
127
- exports.buildUnionTypeNode = buildUnionTypeNode;
128
132
  function buildIntersectionTypeNode(types, terminate) {
129
133
  const node = ts.factory.createIntersectionTypeNode(types);
130
134
  if (terminate) {
@@ -132,7 +136,6 @@ function buildIntersectionTypeNode(types, terminate) {
132
136
  }
133
137
  return ts.factory.createParenthesizedType(node);
134
138
  }
135
- exports.buildIntersectionTypeNode = buildIntersectionTypeNode;
136
139
  function buildTupleTypeNode(types, minItems, maxItems, additionalItems) {
137
140
  function typesIsArray(types) {
138
141
  return Array.isArray(types);
@@ -172,7 +175,6 @@ function buildTupleTypeNode(types, minItems, maxItems, additionalItems) {
172
175
  }
173
176
  return ts.factory.createTupleTypeNode(nodes);
174
177
  }
175
- exports.buildTupleTypeNode = buildTupleTypeNode;
176
178
  function buildTypeReferenceNode(schema, currentSchema) {
177
179
  const typeName = getTypename(schema.id, currentSchema);
178
180
  let node;
@@ -189,7 +191,6 @@ function buildTypeReferenceNode(schema, currentSchema) {
189
191
  }
190
192
  return ts.factory.createTypeReferenceNode(node, undefined);
191
193
  }
192
- exports.buildTypeReferenceNode = buildTypeReferenceNode;
193
194
  function getTypename(id, baseSchema) {
194
195
  const result = id.toNames();
195
196
  const baseId = baseSchema.id;
@@ -225,7 +226,6 @@ function addComment(node, schema, terminate) {
225
226
  return ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, result, true);
226
227
  }
227
228
  }
228
- exports.addComment = addComment;
229
229
  function getComment(schema) {
230
230
  const content = schema.content;
231
231
  let comments = [];
@@ -281,7 +281,6 @@ function addOptionalInformation(node, schema, terminate) {
281
281
  : ts.SyntaxKind.MultiLineCommentTrivia;
282
282
  return ts.addSyntheticTrailingComment(node, kind, comment, false);
283
283
  }
284
- exports.addOptionalInformation = addOptionalInformation;
285
284
  function getLastTypeName(id) {
286
285
  var _a;
287
286
  const names = id.toNames();
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.showConfig = exports.clearToDefault = exports.setConfig = void 0;
3
+ exports.setConfig = setConfig;
4
+ exports.clearToDefault = clearToDefault;
5
+ exports.showConfig = showConfig;
4
6
  const typescript_1 = require("typescript");
5
7
  const type_1 = require("./type");
6
8
  const defaultConfig = {
@@ -19,11 +21,9 @@ let config = Object.assign({}, defaultConfig);
19
21
  function setConfig(input) {
20
22
  config = Object.assign(config, input);
21
23
  }
22
- exports.setConfig = setConfig;
23
24
  function clearToDefault() {
24
25
  setConfig(defaultConfig);
25
26
  }
26
- exports.clearToDefault = clearToDefault;
27
27
  async function showConfig(version, c) {
28
28
  var _a, _b, _c;
29
29
  console.log('Version: ' + version);
@@ -65,7 +65,6 @@ async function showConfig(version, c) {
65
65
  }
66
66
  console.log();
67
67
  }
68
- exports.showConfig = showConfig;
69
68
  function showScriptTarget(target) {
70
69
  switch (target) {
71
70
  case typescript_1.ScriptTarget.ES3:
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SchemaId = void 0;
4
+ exports.default = dtsGenerator;
4
5
  const tslib_1 = require("tslib");
5
6
  const config_1 = require("./config");
6
7
  const dtsGenerator_1 = tslib_1.__importDefault(require("./dtsGenerator"));
@@ -14,4 +15,3 @@ async function dtsGenerator(options) {
14
15
  const generator = new dtsGenerator_1.default(options.contents);
15
16
  return await generator.generate();
16
17
  }
17
- exports.default = dtsGenerator;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectSchemaType = exports.searchAllSubSchema = exports.setId = exports.getId = exports.getSubSchema = void 0;
3
+ exports.getSubSchema = getSubSchema;
4
+ exports.getId = getId;
5
+ exports.setId = setId;
6
+ exports.searchAllSubSchema = searchAllSubSchema;
7
+ exports.selectSchemaType = selectSchemaType;
4
8
  const tslib_1 = require("tslib");
5
9
  const JsonPointer = tslib_1.__importStar(require("../jsonPointer"));
6
10
  const schemaId_1 = tslib_1.__importDefault(require("./schemaId"));
@@ -32,7 +36,6 @@ function getSubSchema(rootSchema, pointer, id) {
32
36
  rootSchema,
33
37
  };
34
38
  }
35
- exports.getSubSchema = getSubSchema;
36
39
  const Draft04Id = 'id';
37
40
  const Draft07Id = '$id';
38
41
  function getId(type, content) {
@@ -44,7 +47,6 @@ function getId(type, content) {
44
47
  return (_b = content[Draft07Id]) !== null && _b !== void 0 ? _b : '';
45
48
  }
46
49
  }
47
- exports.getId = getId;
48
50
  function setId(type, content, id) {
49
51
  var _a, _b;
50
52
  if ((0, type_1.isJsonSchemaDraft04)(content, type)) {
@@ -54,7 +56,6 @@ function setId(type, content, id) {
54
56
  (_b = content[Draft07Id]) !== null && _b !== void 0 ? _b : (content[Draft07Id] = id);
55
57
  }
56
58
  }
57
- exports.setId = setId;
58
59
  function searchAllSubSchema(schema, onFoundSchema, onFoundReference) {
59
60
  const walkArray = (array, paths, parentIds) => {
60
61
  if (array == null) {
@@ -226,7 +227,7 @@ function searchAllSubSchema(schema, onFoundSchema, onFoundReference) {
226
227
  }
227
228
  if ('schema' in response) {
228
229
  const s = response.schema;
229
- if (s != null && s.type === 'file') {
230
+ if ((s === null || s === void 0 ? void 0 : s.type) === 'file') {
230
231
  return;
231
232
  }
232
233
  setSubId(s, keys);
@@ -385,7 +386,6 @@ function searchAllSubSchema(schema, onFoundSchema, onFoundReference) {
385
386
  }
386
387
  walk(schema.content, ['#'], []);
387
388
  }
388
- exports.searchAllSubSchema = searchAllSubSchema;
389
389
  function selectSchemaType(content) {
390
390
  var _a;
391
391
  if (typeof content === 'boolean') {
@@ -435,4 +435,3 @@ function selectSchemaType(content) {
435
435
  }
436
436
  return { type: 'Draft04' };
437
437
  }
438
- exports.selectSchemaType = selectSchemaType;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as url from 'url';
3
2
  export default class SchemaId {
4
3
  readonly inputId: string;
package/dist/core/type.js CHANGED
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadPlugin = exports.parseFileContent = exports.readSchemaFromUrl = exports.readSchemasFromFile = exports.readSchemaFromStdin = exports.parseSchema = exports.isJsonSchemaDraft04 = void 0;
3
+ exports.isJsonSchemaDraft04 = isJsonSchemaDraft04;
4
+ exports.parseSchema = parseSchema;
5
+ exports.readSchemaFromStdin = readSchemaFromStdin;
6
+ exports.readSchemasFromFile = readSchemasFromFile;
7
+ exports.readSchemaFromUrl = readSchemaFromUrl;
8
+ exports.parseFileContent = parseFileContent;
9
+ exports.loadPlugin = loadPlugin;
4
10
  const tslib_1 = require("tslib");
5
11
  const fs = tslib_1.__importStar(require("fs"));
6
12
  const path_1 = require("path");
@@ -12,7 +18,6 @@ exports.ts = require("typescript");
12
18
  function isJsonSchemaDraft04(_content, type) {
13
19
  return type === 'Draft04';
14
20
  }
15
- exports.isJsonSchemaDraft04 = isJsonSchemaDraft04;
16
21
  function parseSchema(content, url) {
17
22
  const { type, openApiVersion } = (0, jsonSchema_1.selectSchemaType)(content);
18
23
  let id;
@@ -29,13 +34,11 @@ function parseSchema(content, url) {
29
34
  content,
30
35
  };
31
36
  }
32
- exports.parseSchema = parseSchema;
33
37
  async function readSchemaFromStdin() {
34
38
  const data = await (0, utils_1.readStream)(process.stdin);
35
39
  const content = parseFileContent(data);
36
40
  return parseSchema(content);
37
41
  }
38
- exports.readSchemaFromStdin = readSchemaFromStdin;
39
42
  async function readSchemasFromFile(pattern) {
40
43
  const files = await (0, utils_1.globFiles)(pattern);
41
44
  return Promise.all(files.map(async (file) => {
@@ -46,13 +49,11 @@ async function readSchemasFromFile(pattern) {
46
49
  return parseSchema(content);
47
50
  }));
48
51
  }
49
- exports.readSchemasFromFile = readSchemasFromFile;
50
52
  async function readSchemaFromUrl(url) {
51
53
  const data = await (0, utils_1.readUrl)(url);
52
54
  const content = parseFileContent(data, url);
53
55
  return parseSchema(content, url);
54
56
  }
55
- exports.readSchemaFromUrl = readSchemaFromUrl;
56
57
  function parseFileContent(content, filename) {
57
58
  const ext = filename ? (0, path_1.extname)(filename).toLowerCase() : '';
58
59
  const maybeYaml = ext === '.yaml' || ext === '.yml';
@@ -73,7 +74,6 @@ function parseFileContent(content, filename) {
73
74
  }
74
75
  }
75
76
  }
76
- exports.parseFileContent = parseFileContent;
77
77
  function deepCopy(obj) {
78
78
  return JSON.parse(JSON.stringify(obj));
79
79
  }
@@ -98,4 +98,3 @@ async function loadPlugin(name, option) {
98
98
  }
99
99
  return plugin;
100
100
  }
101
- exports.loadPlugin = loadPlugin;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildTypeTree = void 0;
3
+ exports.buildTypeTree = buildTypeTree;
4
4
  function buildTypeTree(schemas) {
5
5
  const tree = buildTree();
6
6
  for (const type of schemas) {
@@ -11,7 +11,6 @@ function buildTypeTree(schemas) {
11
11
  }
12
12
  return tree;
13
13
  }
14
- exports.buildTypeTree = buildTypeTree;
15
14
  function setTypeToTree(tree, paths, type) {
16
15
  if (paths.length === 0) {
17
16
  throw new Error('The paths is nothing for set the type to TypeTree.');
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mergeSchema = exports.checkValidMIMEType = exports.reduceTypes = exports.toTSType = void 0;
3
+ exports.toTSType = toTSType;
4
+ exports.reduceTypes = reduceTypes;
5
+ exports.checkValidMIMEType = checkValidMIMEType;
6
+ exports.mergeSchema = mergeSchema;
4
7
  const tslib_1 = require("tslib");
5
8
  const debug_1 = tslib_1.__importDefault(require("debug"));
6
9
  const ts = tslib_1.__importStar(require("typescript"));
@@ -33,7 +36,6 @@ function toTSType(type, debugSource) {
33
36
  throw new Error('unknown type: ' + type);
34
37
  }
35
38
  }
36
- exports.toTSType = toTSType;
37
39
  function reduceTypes(types) {
38
40
  if (types.length < 2) {
39
41
  return types;
@@ -41,7 +43,6 @@ function reduceTypes(types) {
41
43
  const set = new Set(types);
42
44
  return Array.from(set.values());
43
45
  }
44
- exports.reduceTypes = reduceTypes;
45
46
  function checkValidMIMEType(mime) {
46
47
  var _a;
47
48
  const type = (_a = mime.toLowerCase().split(';')[0]) === null || _a === void 0 ? void 0 : _a.trim();
@@ -62,7 +63,6 @@ function checkValidMIMEType(mime) {
62
63
  }
63
64
  return /^application\/(?:[a-z0-9-_.]+\+)?json5?$/.test(type);
64
65
  }
65
- exports.checkValidMIMEType = checkValidMIMEType;
66
66
  function mergeSchema(a, b) {
67
67
  if ('$ref' in a || '$ref' in b) {
68
68
  a.$ref = b.$ref || a.$ref;
@@ -87,4 +87,3 @@ function mergeSchema(a, b) {
87
87
  });
88
88
  return true;
89
89
  }
90
- exports.mergeSchema = mergeSchema;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toTypeName = exports.toValidIdentifier = exports.checkInvalidCharacter = void 0;
3
+ exports.checkInvalidCharacter = checkInvalidCharacter;
4
+ exports.toValidIdentifier = toValidIdentifier;
5
+ exports.toTypeName = toTypeName;
4
6
  const typescript_1 = require("typescript");
5
7
  function checkInvalidCharacter(text, target) {
6
8
  const firstCharCode = text.charCodeAt(0);
@@ -15,7 +17,6 @@ function checkInvalidCharacter(text, target) {
15
17
  }
16
18
  return true;
17
19
  }
18
- exports.checkInvalidCharacter = checkInvalidCharacter;
19
20
  function toValidIdentifier(text, target) {
20
21
  if (/^\d/.test(text)) {
21
22
  text = '$' + text;
@@ -43,7 +44,6 @@ function toValidIdentifier(text, target) {
43
44
  }
44
45
  return res || '_';
45
46
  }
46
- exports.toValidIdentifier = toValidIdentifier;
47
47
  function toTypeName(text, target) {
48
48
  if (/^\d/.test(text)) {
49
49
  text = '$' + text;
@@ -75,7 +75,6 @@ function toTypeName(text, target) {
75
75
  }
76
76
  return res || '_';
77
77
  }
78
- exports.toTypeName = toTypeName;
79
78
  const unicodeES3IdentifierStart = [
80
79
  170, 170, 181, 181, 186, 186, 192, 214, 216, 246, 248, 543, 546, 563, 592,
81
80
  685, 688, 696, 699, 705, 720, 721, 736, 740, 750, 750, 890, 890, 902, 902,
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tilde = exports.parse = exports.set = exports.get = void 0;
3
+ exports.get = get;
4
+ exports.set = set;
5
+ exports.parse = parse;
6
+ exports.tilde = tilde;
4
7
  function get(obj, path, isCreateOnNotExists = false) {
5
8
  if (path.length === 0) {
6
9
  return obj;
@@ -23,7 +26,6 @@ function get(obj, path, isCreateOnNotExists = false) {
23
26
  }
24
27
  return o[lastKey];
25
28
  }
26
- exports.get = get;
27
29
  function set(obj, path, value) {
28
30
  if (path.length === 0) {
29
31
  return;
@@ -41,7 +43,6 @@ function set(obj, path, value) {
41
43
  }
42
44
  o[lastKey] = value;
43
45
  }
44
- exports.set = set;
45
46
  function parse(s) {
46
47
  if (s.startsWith('#')) {
47
48
  s = s.substring(1);
@@ -52,7 +53,6 @@ function parse(s) {
52
53
  }
53
54
  return path.map((key) => untilde(key));
54
55
  }
55
- exports.parse = parse;
56
56
  function untilde(key) {
57
57
  return key.replace(/~(0|1)/g, (match) => {
58
58
  switch (match) {
@@ -68,4 +68,3 @@ function untilde(key) {
68
68
  function tilde(key) {
69
69
  return key.replace(/~/, '~0').replace(/\//g, '~1');
70
70
  }
71
- exports.tilde = tilde;
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { GlobOptions } from 'glob';
4
2
  import { CommandOptions } from './commandOptions';
5
3
  import { PartialConfig } from './core/config';
package/dist/utils.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readConfig = exports.globFiles = exports.buildProxyOptions = exports.readUrl = exports.readStream = void 0;
3
+ exports.readStream = readStream;
4
+ exports.readUrl = readUrl;
5
+ exports.buildProxyOptions = buildProxyOptions;
6
+ exports.globFiles = globFiles;
7
+ exports.readConfig = readConfig;
4
8
  const tslib_1 = require("tslib");
5
9
  const fs = tslib_1.__importStar(require("fs"));
6
10
  const url_1 = require("url");
@@ -18,7 +22,6 @@ function readStream(stream, encoding = 'utf8') {
18
22
  stream.on('error', (error) => reject(error));
19
23
  });
20
24
  }
21
- exports.readStream = readStream;
22
25
  async function readUrl(url) {
23
26
  const init = buildProxyOptions(url);
24
27
  const res = await fetch(url, init);
@@ -28,7 +31,6 @@ async function readUrl(url) {
28
31
  }
29
32
  return data;
30
33
  }
31
- exports.readUrl = readUrl;
32
34
  function noProxy(url) {
33
35
  if (process.env.NO_PROXY) {
34
36
  for (const domain of process.env.NO_PROXY.split(/[, ]+/)) {
@@ -55,7 +57,6 @@ function buildProxyOptions(url) {
55
57
  }
56
58
  return undefined;
57
59
  }
58
- exports.buildProxyOptions = buildProxyOptions;
59
60
  async function globFiles(pattern, options) {
60
61
  const result = [];
61
62
  for await (const r of (0, glob_1.globIterate)(pattern, options !== null && options !== void 0 ? options : {})) {
@@ -68,9 +69,9 @@ async function globFiles(pattern, options) {
68
69
  }
69
70
  return result;
70
71
  }
71
- exports.globFiles = globFiles;
72
72
  function readConfig(options) {
73
- var _a;
73
+ var _a, _b, _c, _d;
74
+ var _e, _f;
74
75
  let pc = {};
75
76
  const configFile = (_a = options.configFile) !== null && _a !== void 0 ? _a : commandOptions_1.defaultConfigFile;
76
77
  try {
@@ -82,24 +83,22 @@ function readConfig(options) {
82
83
  console.error('Error to load config file from ' + options.configFile);
83
84
  }
84
85
  }
85
- if (pc.input == null) {
86
- pc.input = {
87
- files: [],
88
- urls: [],
89
- stdin: false,
90
- };
91
- }
86
+ (_b = pc.input) !== null && _b !== void 0 ? _b : (pc.input = {
87
+ files: [],
88
+ urls: [],
89
+ stdin: false,
90
+ });
92
91
  if (options.files.length > 0) {
93
92
  pc.input.files = options.files;
94
93
  }
95
- else if (pc.input.files == null) {
96
- pc.input.files = [];
94
+ else {
95
+ (_c = (_e = pc.input).files) !== null && _c !== void 0 ? _c : (_e.files = []);
97
96
  }
98
97
  if (options.urls.length > 0) {
99
98
  pc.input.urls = options.urls;
100
99
  }
101
- else if (pc.input.urls == null) {
102
- pc.input.urls = [];
100
+ else {
101
+ (_d = (_f = pc.input).urls) !== null && _d !== void 0 ? _d : (_f.urls = []);
103
102
  }
104
103
  if (options.stdin != null) {
105
104
  pc.input.stdin = options.stdin;
@@ -121,7 +120,6 @@ function readConfig(options) {
121
120
  pc.outputAST = !!options.outputAST;
122
121
  return pc;
123
122
  }
124
- exports.readConfig = readConfig;
125
123
  function loadJSON(file) {
126
124
  const content = fs.readFileSync(file, 'utf-8');
127
125
  return JSON.parse(content);