@vkontakte/api-schema-typescript-generator 0.13.1 → 0.13.2

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/.eslintrc.json CHANGED
@@ -22,6 +22,16 @@
22
22
  "@typescript-eslint/explicit-member-accessibility": "off",
23
23
  "@typescript-eslint/no-unnecessary-condition": "off",
24
24
  "@typescript-eslint/no-magic-numbers": "off",
25
- "@typescript-eslint/no-extra-parens": "off"
26
- }
25
+ "@typescript-eslint/no-extra-parens": "off",
26
+
27
+ "no-shadow": "off"
28
+ },
29
+ "overrides": [
30
+ {
31
+ "files": ["**/*.ts"],
32
+ "rules": {
33
+ "no-undef": "off"
34
+ }
35
+ }
36
+ ]
27
37
  }
@@ -0,0 +1,2 @@
1
+ yarn.lock @VKCOM/vk-sec
2
+ .yarnrc @VKCOM/vk-sec
@@ -37,6 +37,19 @@ class APITypingsGenerator {
37
37
  };
38
38
  this.resultFiles = {};
39
39
  }
40
+ needEmit;
41
+ outDirPath;
42
+ methodsPattern;
43
+ methodsDefinitions;
44
+ methodsList;
45
+ objects;
46
+ responses;
47
+ visitedRefs;
48
+ generatedObjects;
49
+ methodFilesMap;
50
+ exports;
51
+ ignoredResponses;
52
+ resultFiles;
40
53
  convertJSONSchemaDictionary(objects) {
41
54
  const dictionary = {};
42
55
  Object.keys(objects).forEach((name) => {
@@ -340,7 +353,7 @@ class APITypingsGenerator {
340
353
  }
341
354
  getResponseCodeBlockAsType(object, response) {
342
355
  const { imports, value, codeBlocks, description, } = typeString_1.generateTypeString(response, this.objects, {
343
- objectParentName: ' ',
356
+ objectParentName: ' ', // TODO: Refactor
344
357
  });
345
358
  const codeBlock = new TypeCodeBlock_1.TypeCodeBlock({
346
359
  type: TypeCodeBlock_1.TypeScriptCodeTypes.Type,
@@ -8,6 +8,7 @@ class CommentCodeBlock extends BaseCodeBlock_1.BaseCodeBlock {
8
8
  super();
9
9
  this.lines = lines;
10
10
  }
11
+ lines;
11
12
  appendLines(lines) {
12
13
  this.lines = [
13
14
  ...this.lines,
@@ -68,6 +68,20 @@ class SchemaObject {
68
68
  this.allOf = object.allOf.map((item) => new SchemaObject(name, item));
69
69
  }
70
70
  }
71
+ name;
72
+ parentObjectName;
73
+ type;
74
+ description;
75
+ ref;
76
+ required;
77
+ isRequired;
78
+ enum;
79
+ enumNames;
80
+ properties;
81
+ parameters;
82
+ items;
83
+ oneOf;
84
+ allOf;
71
85
  setName(name) {
72
86
  this.name = name;
73
87
  if (Array.isArray(this.properties)) {
@@ -26,6 +26,15 @@ class TypeCodeBlock extends BaseCodeBlock_1.BaseCodeBlock {
26
26
  this.value = options.value;
27
27
  this.needExport = options.needExport;
28
28
  }
29
+ options;
30
+ type;
31
+ refName;
32
+ interfaceName;
33
+ extendsInterfaces;
34
+ description;
35
+ properties;
36
+ value;
37
+ needExport;
29
38
  addProperty(property) {
30
39
  this.properties.push(property);
31
40
  }
@@ -13,6 +13,7 @@ function normalizeMethodInfo(method) {
13
13
  // For method params "boolean" type means 1 or 0
14
14
  // Real "false" boolean value will be detected by API as true
15
15
  if (parameter.type === 'boolean') {
16
+ // @ts-expect-error
16
17
  delete parameter.type;
17
18
  parameter.$ref = constants_1.baseBoolIntRef;
18
19
  }
package/dist/helpers.js CHANGED
@@ -14,7 +14,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
14
14
  var __importStar = (this && this.__importStar) || function (mod) {
15
15
  if (mod && mod.__esModule) return mod;
16
16
  var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
@@ -58,6 +58,8 @@ function writeFile(filePath, code, insertAutoGeneratedNote = true) {
58
58
  '/**',
59
59
  ' * This is auto-generated file, don\'t modify this file manually',
60
60
  ' */',
61
+ // '/* eslint-disable max-len */',
62
+ // '/* eslint-disable @typescript-eslint/no-empty-interface */',
61
63
  ].join(constants_1.newLineChar) + constants_1.newLineChar.repeat(2) + code.trim();
62
64
  }
63
65
  fs_1.default.mkdirSync(filePath.replace(path_1.default.basename(filePath), ''), { recursive: true });
@@ -124,7 +126,7 @@ function areQuotesNeededForProperty(name) {
124
126
  if (isPatternProperty(name)) {
125
127
  return false;
126
128
  }
127
- if (/[&]/.test(name)) {
129
+ if (/[&-]/.test(name)) {
128
130
  return true;
129
131
  }
130
132
  return !(/^[a-z_]([a-z0-9_])+$/i.test(name) || /^[a-z_]/i.test(name));
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const helpers_1 = require("./helpers");
4
+ test('areQuotesNeededForProperty', () => {
5
+ expect(helpers_1.areQuotesNeededForProperty('user_id')).toBe(false);
6
+ expect(helpers_1.areQuotesNeededForProperty('uuid4')).toBe(false);
7
+ expect(helpers_1.areQuotesNeededForProperty('_foo')).toBe(false);
8
+ expect(helpers_1.areQuotesNeededForProperty('4uuid')).toBe(true);
9
+ expect(helpers_1.areQuotesNeededForProperty('user-id')).toBe(true);
10
+ expect(helpers_1.areQuotesNeededForProperty('user&id')).toBe(true);
11
+ expect(helpers_1.areQuotesNeededForProperty('идентификатор')).toBe(true);
12
+ });
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest',
4
+ testEnvironment: 'node',
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/api-schema-typescript-generator",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "license": "MIT",
5
5
  "description": "VK API TypeScript generator",
6
6
  "author": {
@@ -23,7 +23,8 @@
23
23
  ],
24
24
  "repository": "https://github.com/VKCOM/api-schema-typescript-generator",
25
25
  "engines": {
26
- "node": ">=12.0.0"
26
+ "node": ">=12.0.0",
27
+ "yarn": "^1.21.1"
27
28
  },
28
29
  "bin": {
29
30
  "vk-api-schema-typescript-generator": "./bin/vk-api-schema-typescript-generator.js"
@@ -32,7 +33,7 @@
32
33
  "clear": "rimraf dist/*",
33
34
  "build": "yarn clear && tsc",
34
35
  "watch": "yarn clear && tsc --watch",
35
- "test": "tsc --noEmit && eslint src --ext .ts"
36
+ "test": "jest && tsc --noEmit && eslint src --ext .ts"
36
37
  },
37
38
  "pre-commit": [
38
39
  "test"
@@ -42,15 +43,18 @@
42
43
  "chalk": "4.1.0"
43
44
  },
44
45
  "devDependencies": {
46
+ "@types/jest": "^28.1.5",
45
47
  "@types/node": "^14.0.13",
46
- "@typescript-eslint/eslint-plugin": "2.34.0",
47
- "@typescript-eslint/parser": "2.0.0",
48
- "@vkontakte/eslint-config": "2.5.0",
49
- "eslint": "6.8.0",
50
- "eslint-plugin-react": "7.19.0",
51
- "eslint-plugin-react-hooks": "3.0.0",
48
+ "@typescript-eslint/eslint-plugin": "5.30.6",
49
+ "@typescript-eslint/parser": "5.30.6",
50
+ "@vkontakte/eslint-config": "3.1.0",
51
+ "eslint": "8.19.0",
52
+ "eslint-plugin-react": "7.30.1",
53
+ "eslint-plugin-react-hooks": "4.6.0",
54
+ "jest": "28.1.3",
52
55
  "pre-commit": "1.2.2",
53
56
  "rimraf": "^3.0.2",
54
- "typescript": "3.9.5"
57
+ "ts-jest": "^28.0.6",
58
+ "typescript": "4.3.5"
55
59
  }
56
60
  }
@@ -18,6 +18,7 @@ export function normalizeMethodInfo(method: Schema.Method): NormalizeMethodInfoR
18
18
  // For method params "boolean" type means 1 or 0
19
19
  // Real "false" boolean value will be detected by API as true
20
20
  if (parameter.type === 'boolean') {
21
+ // @ts-expect-error
21
22
  delete parameter.type;
22
23
  parameter.$ref = baseBoolIntRef;
23
24
  }
@@ -0,0 +1,12 @@
1
+ import { areQuotesNeededForProperty } from './helpers';
2
+
3
+ test('areQuotesNeededForProperty', () => {
4
+ expect(areQuotesNeededForProperty('user_id')).toBe(false);
5
+ expect(areQuotesNeededForProperty('uuid4')).toBe(false);
6
+ expect(areQuotesNeededForProperty('_foo')).toBe(false);
7
+
8
+ expect(areQuotesNeededForProperty('4uuid')).toBe(true);
9
+ expect(areQuotesNeededForProperty('user-id')).toBe(true);
10
+ expect(areQuotesNeededForProperty('user&id')).toBe(true);
11
+ expect(areQuotesNeededForProperty('идентификатор')).toBe(true);
12
+ });
package/src/helpers.ts CHANGED
@@ -111,9 +111,10 @@ export function areQuotesNeededForProperty(name: string | number): boolean {
111
111
  return false;
112
112
  }
113
113
 
114
- if (/[&]/.test(name)) {
114
+ if (/[&-]/.test(name)) {
115
115
  return true;
116
116
  }
117
+
117
118
  return !(/^[a-z_]([a-z0-9_])+$/i.test(name) || /^[a-z_]/i.test(name));
118
119
  }
119
120