From c3b0b46512ceaeb69b46d6367d742b3dc2d2d719 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 29 Nov 2023 13:29:25 +0530 Subject: [PATCH 1/5] added optional null in generated types if the given field is optional --- src/lib/tsgen/factory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/tsgen/factory.ts b/src/lib/tsgen/factory.ts index e93a230..8c0c319 100644 --- a/src/lib/tsgen/factory.ts +++ b/src/lib/tsgen/factory.ts @@ -219,7 +219,7 @@ export default function (userOptions: TSGenOptions) { return [ field.uid + op_required(field.mandatory) + ':', - fieldType || visit_field_type(field) + ';', + fieldType || visit_field_type(field), field.mandatory?'':'| null', ';' ].join(' ') } @@ -272,7 +272,7 @@ export default function (userOptions: TSGenOptions) { } function type_text() { - return 'string' + return 'string' } function type_number() { From 00684c4eb9896c61a0ae70580ec8b3d2327ba454 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 29 Nov 2023 13:31:15 +0530 Subject: [PATCH 2/5] version bump --- package-lock.json | 249 +++++++++++++++++++++++++++++----------------- package.json | 2 +- 2 files changed, 159 insertions(+), 92 deletions(-) diff --git a/package-lock.json b/package-lock.json index d27d955..4fb1c0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "contentstack-cli-tsgen", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack-cli-tsgen", - "version": "2.2.0", + "version": "2.2.1", "license": "MIT", "dependencies": { "@contentstack/cli-command": "^1.2.13", @@ -50,17 +50,89 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.5.tgz", - "integrity": "sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.4.tgz", + "integrity": "sha512-r1IONyb6Ia+jYR2vvIDhdWdlTGhqbBoFqLTQidzZ4kepUFH15ejXvFHxCVbtl7BOXIudsIubf4E81xeA3h3IXA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.22.5" + "@babel/highlight": "^7.23.4", + "chalk": "^2.4.2" }, "engines": { "node": ">=6.9.0" } }, + "node_modules/@babel/code-frame/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "dev": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/@babel/code-frame/node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", + "dev": true + }, + "node_modules/@babel/code-frame/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/@babel/code-frame/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/code-frame/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/compat-data": { "version": "7.22.5", "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.22.5.tgz", @@ -110,12 +182,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.5.tgz", - "integrity": "sha512-+lcUbnTRhd0jOewtFSedLyiPsD5tswKkbgcezOqqWFUVNEwoUTlpPOBmvhG7OXWLR4jMdv0czPGH5XbflnD1EA==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.4.tgz", + "integrity": "sha512-esuS49Cga3HcThFNebGhlgsrVLkvhqvYDTzgjfFFlHJcIfLe5jFmRRfCQ1KuBfc4Jrtn3ndLgKWAKjBE+IraYQ==", "dev": true, "dependencies": { - "@babel/types": "^7.22.5", + "@babel/types": "^7.23.4", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -167,22 +239,22 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz", - "integrity": "sha512-XGmhECfVA/5sAt+H+xpSg0mfrHq6FzNr9Oxh7PSEBBRUb/mL7Kz3NICXb194rCqAEdxkhPT1a88teizAFyvk8Q==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-function-name": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz", - "integrity": "sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "dev": true, "dependencies": { - "@babel/template": "^7.22.5", - "@babel/types": "^7.22.5" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" }, "engines": { "node": ">=6.9.0" @@ -253,9 +325,9 @@ } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.5.tgz", - "integrity": "sha512-thqK5QFghPKWLhAV321lxF95yCg2K3Ob5yw+M3VHWfdia0IkPXUtoLH8x/6Fh486QUvzhb8YOWHChTVen2/PoQ==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "dev": true, "dependencies": { "@babel/types": "^7.22.5" @@ -265,18 +337,18 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", - "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.23.4.tgz", + "integrity": "sha512-803gmbQdqwdf4olxrX4AJyFBV/RTr3rSmOj0rKwesmzlfhYNDEs+/iOcznzpNWlJlIlTJC2QfPFcHB6DlzdVLQ==", "dev": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz", - "integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "dev": true, "engines": { "node": ">=6.9.0" @@ -306,13 +378,13 @@ } }, "node_modules/@babel/highlight": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.5.tgz", - "integrity": "sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.23.4.tgz", + "integrity": "sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.22.5", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" }, "engines": { @@ -391,9 +463,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.5.tgz", - "integrity": "sha512-DFZMC9LJUG9PLOclRC32G63UXwzqS2koQC8dkx+PLdmt1xSePYpbT/NbsrJy8Q/muXz7o/h/d4A7Fuyixm559Q==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.4.tgz", + "integrity": "sha512-vf3Xna6UEprW+7t6EtOmFpHNAuxw3xqPZghy+brsnusscJRW5BMUzzHZc5ICjULee81WeUV2jjakG09MDglJXQ==", "dev": true, "bin": { "parser": "bin/babel-parser.js" @@ -550,33 +622,33 @@ } }, "node_modules/@babel/template": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.5.tgz", - "integrity": "sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.22.5", - "@babel/parser": "^7.22.5", - "@babel/types": "^7.22.5" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.22.5.tgz", - "integrity": "sha512-7DuIjPgERaNo6r+PZwItpjCZEa5vyw4eJGufeLxrPdBXBoLcCJCIasvK6pK/9DVNrLZTLFhUGqaC6X/PA007TQ==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.4.tgz", + "integrity": "sha512-IYM8wSUwunWTB6tFC2dkKZhxbIjHoWemdK+3f8/wq8aKhbUscxD5MX72ubd90fxvFknaLPeGw5ycU84V1obHJg==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.22.5", - "@babel/generator": "^7.22.5", - "@babel/helper-environment-visitor": "^7.22.5", - "@babel/helper-function-name": "^7.22.5", + "@babel/code-frame": "^7.23.4", + "@babel/generator": "^7.23.4", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.5", - "@babel/parser": "^7.22.5", - "@babel/types": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.4", + "@babel/types": "^7.23.4", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -585,13 +657,13 @@ } }, "node_modules/@babel/types": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz", - "integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==", + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.4.tgz", + "integrity": "sha512-7uIFwVYpoplT5jp/kVv6EF93VaJ8H+Yn5IczYiaAi98ajzjfoZfslet/e0sLh+wVBjb2qqIut1b0S26VSafsSQ==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.22.5", - "@babel/helper-validator-identifier": "^7.22.5", + "@babel/helper-string-parser": "^7.23.4", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, "engines": { @@ -641,13 +713,13 @@ } }, "node_modules/@contentstack/cli-utilities": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/@contentstack/cli-utilities/-/cli-utilities-1.5.3.tgz", - "integrity": "sha512-c5iv9o0rOYdNN3rlQd2hOoQHIqpoU2MqM/jWYzqtjH1MttJsf/SaEs1Zjb5hO1FHHuhznEXpPQHM4PBZ5BsMJA==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/@contentstack/cli-utilities/-/cli-utilities-1.5.7.tgz", + "integrity": "sha512-gAM6xtrrAcEcvwx/R6pEImyMNnxBjjEWXe+RNYGaRIS/BfXH542waDWzs/9E8UO9SSZIjomnTd0hVO86+mborg==", "dependencies": { - "@contentstack/management": "~1.10.2", + "@contentstack/management": "~1.12.0", "@oclif/core": "^2.9.3", - "axios": "1.3.4", + "axios": "^1.6.0", "chalk": "^4.0.0", "cli-cursor": "^3.1.0", "cli-table": "^0.3.11", @@ -657,11 +729,13 @@ "inquirer": "8.2.4", "inquirer-search-checkbox": "^1.0.0", "inquirer-search-list": "^1.2.6", + "klona": "^2.0.6", "lodash": "^4.17.15", "mkdirp": "^1.0.4", "open": "^8.4.2", "ora": "^5.4.0", "rxjs": "^6.6.7", + "traverse": "^0.6.7", "unique-string": "^2.0.0", "uuid": "^9.0.0", "winston": "^3.7.2", @@ -691,11 +765,11 @@ } }, "node_modules/@contentstack/management": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.10.2.tgz", - "integrity": "sha512-jO24EqcCJhOjqdsqw8y3T0SPPAd0DG4BByjUcV0S28W2yoa8aBbcjcbZioRPzRLYKTmZWsAZissl18cIJm5djQ==", + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.12.0.tgz", + "integrity": "sha512-+L+WVhSYEtfdG9v794TjLT8Fd6fCB8meqoho666mg1kNufzXcsqr7hjubX5cSL7GcZFdKntkDpZ2RaOnTHReJg==", "dependencies": { - "axios": "^1.4.0", + "axios": "^1.5.1", "form-data": "^3.0.1", "lodash": "^4.17.21", "qs": "^6.11.2" @@ -704,29 +778,6 @@ "node": ">=8.0.0" } }, - "node_modules/@contentstack/management/node_modules/axios": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz", - "integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, - "node_modules/@contentstack/management/node_modules/axios/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/@contentstack/utils": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@contentstack/utils/-/utils-1.2.0.tgz", @@ -3391,9 +3442,9 @@ } }, "node_modules/axios": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz", - "integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -8997,6 +9048,14 @@ "node": ">=6" } }, + "node_modules/klona": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/klona/-/klona-2.0.6.tgz", + "integrity": "sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==", + "engines": { + "node": ">= 8" + } + }, "node_modules/kuler": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz", @@ -13793,6 +13852,14 @@ "node": ">=8" } }, + "node_modules/traverse": { + "version": "0.6.7", + "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.6.7.tgz", + "integrity": "sha512-/y956gpUo9ZNCb99YjxG7OaslxZWHfCHAUUfshwqOXmxUIvqLjVO581BT+gM59+QV9tFe6/CGG53tsA1Y7RSdg==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/tree-kill": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", diff --git a/package.json b/package.json index edd1b51..1b65b35 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "contentstack-cli-tsgen", "description": "Generate TypeScript typings from a Stack.", - "version": "2.2.0", + "version": "2.2.1", "author": "Michael Davis", "bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues", "dependencies": { From 5bacf6abd56acbe3eca9ce71269e55181caabed6 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 29 Nov 2023 13:58:42 +0530 Subject: [PATCH 3/5] test cases fix and workflow update --- .github/workflows/node.js.yml | 4 +- tests/tsgen/boolean.test.ts | 38 ++++++++--------- tests/tsgen/defaults.test.ts | 58 ++++++++++++------------- tests/tsgen/global.fields.test.ts | 46 ++++++++++---------- tests/tsgen/group.test.ts | 68 +++++++++++++++--------------- tests/tsgen/isodate.test.ts | 44 +++++++++---------- tests/tsgen/jsdoc.test.ts | 28 ++++++------ tests/tsgen/modular.blocks.test.ts | 50 +++++++++++----------- tests/tsgen/number.test.ts | 46 ++++++++++---------- tests/tsgen/options.test.ts | 32 +++++++------- tests/tsgen/references.test.ts | 8 ++-- tests/tsgen/select.test.ts | 44 +++++++++---------- tests/tsgen/string.test.ts | 42 +++++++++--------- tests/tsgen/taxonomies.test.ts | 43 ++++++++++--------- 14 files changed, 276 insertions(+), 275 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 4ed9131..58c95e8 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -5,9 +5,9 @@ name: Node.js CI on: push: - branches: [ master ] + branches: [ master, development, staging ] pull_request: - branches: [ master ] + branches: [ master, development, staging ] jobs: build: diff --git a/tests/tsgen/boolean.test.ts b/tests/tsgen/boolean.test.ts index a49c0fc..83810b3 100644 --- a/tests/tsgen/boolean.test.ts +++ b/tests/tsgen/boolean.test.ts @@ -1,34 +1,34 @@ -const testData = require('./boolean.ct') +const testData = require("./boolean.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), naming: { - prefix: 'I', + prefix: "I", }, -}) +}); -describe('builtin boolean field', () => { - const result = tsgen(testData.builtinBoolean) +describe("builtin boolean field", () => { + const result = tsgen(testData.builtinBoolean); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - expect(types.javascript).toContain('boolean') - }) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + expect(types.javascript).toContain("boolean"); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IBoolean { /** Version */ version: 2 ; - title: string; - boolean?: boolean; + title: string ; + boolean?: boolean | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/defaults.test.ts b/tests/tsgen/defaults.test.ts index 0fc5ba1..1032277 100644 --- a/tests/tsgen/defaults.test.ts +++ b/tests/tsgen/defaults.test.ts @@ -1,53 +1,53 @@ -const testData = require('./defaults.ct') +const testData = require("./defaults.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), naming: { - prefix: 'I', + prefix: "I", }, -}) +}); -describe('default single content block', () => { - const result = tsgen(testData.defaultSingleContentBlock) +describe("default single content block", () => { + const result = tsgen(testData.defaultSingleContentBlock); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IMetadataSingleContentBlock { /** Version */ version: 2 ; - title: string; + title: string ; }" - `) - }) -}) + `); + }); +}); -describe('default single webpage', () => { - const result = tsgen(testData.defaultSingleWebpage) +describe("default single webpage", () => { + const result = tsgen(testData.defaultSingleWebpage); - test('types', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - expect(types.javascript).toContain('string') - }) + test("types", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + expect(types.javascript).toContain("string"); + }); - test('dependencies', () => { - expect(result.metadata.dependencies.globalFields).toEqual({}) - }) + test("dependencies", () => { + expect(result.metadata.dependencies.globalFields).toEqual({}); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IMetadataSingleWebpage { /** Version */ version: 2 ; - title: string; - url: string; + title: string ; + url: string ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/global.fields.test.ts b/tests/tsgen/global.fields.test.ts index 4e78e7a..128d181 100644 --- a/tests/tsgen/global.fields.test.ts +++ b/tests/tsgen/global.fields.test.ts @@ -1,46 +1,46 @@ -const testData = require('./global.fields.ct') +const testData = require("./global.fields.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), naming: { - prefix: 'I', + prefix: "I", }, -}) +}); -describe('global fields', () => { - const result = tsgen(testData.globalFields) +describe("global fields", () => { + const result = tsgen(testData.globalFields); - test('metadata', () => { - const types = result.metadata.types + test("metadata", () => { + const types = result.metadata.types; - expect([...types.globalFields]).toEqual(expect.arrayContaining(['ISeo'])) - }) + expect([...types.globalFields]).toEqual(expect.arrayContaining(["ISeo"])); + }); - test('global field definition', () => { - const globalField = result.metadata.dependencies.globalFields.ISeo + test("global field definition", () => { + const globalField = result.metadata.dependencies.globalFields.ISeo; expect(globalField.definition).toMatchInlineSnapshot(` "export interface ISeo { /** Version */ version: ; - keywords?: string; - description?: string; + keywords?: string | null ; + description?: string | null ; }" - `) - }) + `); + }); - test('content type definition', () => { + test("content type definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IGlobalFields { /** Version */ version: 2 ; - title: string; - seo?: ISeo; + title: string ; + seo?: ISeo | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/group.test.ts b/tests/tsgen/group.test.ts index 116591d..d5d9369 100644 --- a/tests/tsgen/group.test.ts +++ b/tests/tsgen/group.test.ts @@ -1,56 +1,56 @@ -const testData = require('./group.ct') +const testData = require("./group.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('group', () => { - const result = tsgen(testData.group) +describe("group", () => { + const result = tsgen(testData.group); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); expect([...types.javascript]).toEqual( - expect.arrayContaining(['string', 'number', 'boolean']) - ) - }) + expect.arrayContaining(["string", "number", "boolean"]) + ); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Group { /** Version */ version: 3 ; - title: string; + title: string ; multiple_group_max_limit?: [{ - number?: number; + number?: number | null ; }, { - number?: number; + number?: number | null ; }, { - number?: number; + number?: number | null ; }, { - number?: number; + number?: number | null ; }, { - number?: number; - }]; + number?: number | null ; + }] | null ; multiple_group?: { - single_line?: string; - }[]; + single_line?: string | null ; + }[] | null ; parent_group?: { - rich_text_editor?: string; - multi_line?: string; - single_line?: string; + rich_text_editor?: string | null ; + multi_line?: string | null ; + single_line?: string | null ; child_group?: { - number?: number; - boolean?: boolean; - date?: string; - }; - }; + number?: number | null ; + boolean?: boolean | null ; + date?: string | null ; + } | null ; + } | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/isodate.test.ts b/tests/tsgen/isodate.test.ts index 1ef533f..98302a4 100644 --- a/tests/tsgen/isodate.test.ts +++ b/tests/tsgen/isodate.test.ts @@ -1,38 +1,38 @@ -const testData = require('./isodate.ct') +const testData = require("./isodate.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('builtin isodate field', () => { - const result = tsgen(testData.builtinIsodate) +describe("builtin isodate field", () => { + const result = tsgen(testData.builtinIsodate); /* * Isodates are returned as strings */ - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - expect(types.javascript).toContain('string') - }) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + expect(types.javascript).toContain("string"); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Isodate { /** Version */ version: 2 ; - title: string; - date?: string; - date_required: string; - date_multiple?: string[]; - date_multiple_maxlength?: [string, string, string, string, string]; - date_required_multiple_maxlength: [string, string, string, string, string, string, string, string]; + title: string ; + date?: string | null ; + date_required: string ; + date_multiple?: string[] | null ; + date_multiple_maxlength?: [string, string, string, string, string] | null ; + date_required_multiple_maxlength: [string, string, string, string, string, string, string, string] ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/jsdoc.test.ts b/tests/tsgen/jsdoc.test.ts index 044bcd0..178433a 100644 --- a/tests/tsgen/jsdoc.test.ts +++ b/tests/tsgen/jsdoc.test.ts @@ -1,16 +1,16 @@ -const testData = require('./jsdoc.ct') +const testData = require("./jsdoc.ct"); -import JSDocumentationGenerator from '../../src/lib/tsgen/docgen/jsdoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import JSDocumentationGenerator from "../../src/lib/tsgen/docgen/jsdoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new JSDocumentationGenerator(), -}) +}); -describe('jsdoc', () => { - const result = tsgen(testData.jsdoc) +describe("jsdoc", () => { + const result = tsgen(testData.jsdoc); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "/** Content Type Description */ export interface Jsdoc @@ -18,14 +18,14 @@ describe('jsdoc', () => { /** Version */ version: 3 ; /** Name */ - title: string; + title: string ; /** Age */ - current_age?: number; + current_age?: number | null ; /** City */ - current_city?: string; + current_city?: string | null ; /** State */ - current_state?: string; + current_state?: string | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/modular.blocks.test.ts b/tests/tsgen/modular.blocks.test.ts index 636286d..a77e758 100644 --- a/tests/tsgen/modular.blocks.test.ts +++ b/tests/tsgen/modular.blocks.test.ts @@ -1,38 +1,38 @@ -const testData = require('./modular.blocks.ct') +const testData = require("./modular.blocks.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('modular blocks', () => { - const result = tsgen(testData.modularBlocks) +describe("modular blocks", () => { + const result = tsgen(testData.modularBlocks); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - }) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface ModularBlocks { /** Version */ version: 2 ; - title: string; - url: string; - modular_blocks?: ({string_block: {single_line?: string; - multi_line?: string; - markdown?: string; - rich_text_editor?: string;};string_block_with_options: undefined; - boolean_block: undefined;} | {string_block_with_options: {single_line_textbox_required: string; - single_line_textbox_multiple?: string[];};string_block: undefined; - boolean_block: undefined;} | {boolean_block: {boolean?: boolean;};string_block: undefined; - string_block_with_options: undefined;})[]; + title: string ; + url: string ; + modular_blocks?: ({string_block: {single_line?: string | null ; + multi_line?: string | null ; + markdown?: string | null ; + rich_text_editor?: string | null ;};string_block_with_options: undefined; + boolean_block: undefined;} | {string_block_with_options: {single_line_textbox_required: string ; + single_line_textbox_multiple?: string[] | null ;};string_block: undefined; + boolean_block: undefined;} | {boolean_block: {boolean?: boolean | null ;};string_block: undefined; + string_block_with_options: undefined;})[] | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/number.test.ts b/tests/tsgen/number.test.ts index ffa0114..036dab6 100644 --- a/tests/tsgen/number.test.ts +++ b/tests/tsgen/number.test.ts @@ -1,36 +1,36 @@ -const testData = require('./number.ct') +const testData = require("./number.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('builtin number field', () => { - const result = tsgen(testData.builtinNumber) +describe("builtin number field", () => { + const result = tsgen(testData.builtinNumber); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - expect(types.javascript).toContain('number') - }) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + expect(types.javascript).toContain("number"); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Number { /** Version */ version: 2 ; - title: string; - url: string; - number?: number; - number_required: number; - number_multiple?: number[]; - number_multiple_max_limit?: [number, number, number, number, number, number, number, number, number, number]; - number_required_multiple_max_limit: [number, number, number]; + title: string ; + url: string ; + number?: number | null ; + number_required: number ; + number_multiple?: number[] | null ; + number_multiple_max_limit?: [number, number, number, number, number, number, number, number, number, number] | null ; + number_required_multiple_max_limit: [number, number, number] ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/options.test.ts b/tests/tsgen/options.test.ts index 4ff9df0..7b8b609 100644 --- a/tests/tsgen/options.test.ts +++ b/tests/tsgen/options.test.ts @@ -1,28 +1,28 @@ -const testData = require('./options.ct') +const testData = require("./options.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('all options', () => { - const result = tsgen(testData.options) +describe("all options", () => { + const result = tsgen(testData.options); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Options { /** Version */ version: 4 ; - title: string; - url: string; - single_line_textbox_not_required?: string; - single_line_textbox_required: string; - single_line_textbox_multiple?: string[]; - single_line_textbox_multiple_max_limit?: [string, string, string, string, string]; + title: string ; + url: string ; + single_line_textbox_not_required?: string | null ; + single_line_textbox_required: string ; + single_line_textbox_multiple?: string[] | null ; + single_line_textbox_multiple_max_limit?: [string, string, string, string, string] | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/references.test.ts b/tests/tsgen/references.test.ts index acf9d7b..c0e1f9d 100644 --- a/tests/tsgen/references.test.ts +++ b/tests/tsgen/references.test.ts @@ -27,10 +27,10 @@ describe("references", () => { { /** Version */ version: 5 ; - title: string; - url: string; - single_reference: (IReferenceChild); - multiple_reference?: (IReferenceChild | IBoolean | IBuiltinExample)[]; + title: string ; + url: string ; + single_reference: (IReferenceChild) ; + multiple_reference?: (IReferenceChild | IBoolean | IBuiltinExample)[] | null ; }" `); }); diff --git a/tests/tsgen/select.test.ts b/tests/tsgen/select.test.ts index 4894c4c..8209dd8 100644 --- a/tests/tsgen/select.test.ts +++ b/tests/tsgen/select.test.ts @@ -1,35 +1,35 @@ -const testData = require('./select.ct') +const testData = require("./select.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('select (dropdown)', () => { - const result = tsgen(testData.select) +describe("select (dropdown)", () => { + const result = tsgen(testData.select); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - }) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Select { /** Version */ version: 5 ; - title: string; - select_single_value?: (\\"Option 1\\" | \\"Option 2\\" | \\"Option 3\\"); - select_single_value_required: (\\"Test 1\\" | \\"Test 2\\" | \\"Test 3\\"); - select_single_value_with_quotes?: (\\"\\\\\\"ABC\\\\\\"\\" | \\"A'B'C\\" | \\"\`A\`B\`C\\"); - select_multi_value?: (\\"Multi 1\\" | \\"Multi 2\\" | \\"Multi 3\\")[]; - select_multi_value_required: (\\"Multi Req 1\\" | \\"Multi Req 2\\" | \\"Multi Req 3\\")[]; - select_number_values?: (1 | 2 | 3 | 4); + title: string ; + select_single_value?: (\\"Option 1\\" | \\"Option 2\\" | \\"Option 3\\") | null ; + select_single_value_required: (\\"Test 1\\" | \\"Test 2\\" | \\"Test 3\\") ; + select_single_value_with_quotes?: (\\"\\\\\\"ABC\\\\\\"\\" | \\"A'B'C\\" | \\"\`A\`B\`C\\") | null ; + select_multi_value?: (\\"Multi 1\\" | \\"Multi 2\\" | \\"Multi 3\\")[] | null ; + select_multi_value_required: (\\"Multi Req 1\\" | \\"Multi Req 2\\" | \\"Multi Req 3\\")[] ; + select_number_values?: (1 | 2 | 3 | 4) | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/string.test.ts b/tests/tsgen/string.test.ts index 16ff2c1..3005d41 100644 --- a/tests/tsgen/string.test.ts +++ b/tests/tsgen/string.test.ts @@ -1,34 +1,34 @@ -const testData = require('./string.ct') +const testData = require("./string.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), -}) +}); -describe('builtin string fields', () => { - const result = tsgen(testData.builtinStrings) +describe("builtin string fields", () => { + const result = tsgen(testData.builtinStrings); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(0) - expect([...types.globalFields]).toHaveLength(0) - expect(types.javascript).toContain('string') - }) + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(0); + expect([...types.globalFields]).toHaveLength(0); + expect(types.javascript).toContain("string"); + }); - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface BuiltinStrings { /** Version */ version: 4 ; - title: string; - single_line?: string; - multi_line?: string; - rich_text_editor?: string; - markdown?: string; + title: string ; + single_line?: string | null ; + multi_line?: string | null ; + rich_text_editor?: string | null ; + markdown?: string | null ; }" - `) - }) -}) + `); + }); +}); diff --git a/tests/tsgen/taxonomies.test.ts b/tests/tsgen/taxonomies.test.ts index 9f3812d..6e5f87c 100644 --- a/tests/tsgen/taxonomies.test.ts +++ b/tests/tsgen/taxonomies.test.ts @@ -1,36 +1,37 @@ -const testData = require('./taxonomies.ct') +const testData = require("./taxonomies.ct"); -import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' -import tsgenFactory from '../../src/lib/tsgen/factory' +import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc"; +import tsgenFactory from "../../src/lib/tsgen/factory"; const tsgen = tsgenFactory({ docgen: new NullDocumentationGenerator(), naming: { - prefix: 'I', + prefix: "I", }, -}) +}); -describe('builtin taxonomies field', () => { - const result = tsgen(testData.builtinTaxonomies) +describe("builtin taxonomies field", () => { + const result = tsgen(testData.builtinTaxonomies); + test("metadata", () => { + const types = result.metadata.types; + expect([...types.contentstack]).toHaveLength(1); + expect([...types.globalFields]).toHaveLength(0); + expect([...types.contentstack]).toEqual( + expect.arrayContaining(["ITaxonomy"]) + ); + }); - test('metadata', () => { - const types = result.metadata.types - expect([...types.contentstack]).toHaveLength(1) - expect([...types.globalFields]).toHaveLength(0) - expect([...types.contentstack]).toEqual(expect.arrayContaining(['ITaxonomy'])) - }) - - test('definition', () => { + test("definition", () => { expect(result.definition).toMatchInlineSnapshot(` "export interface ITaxonomy { /** Version */ version: 2 ; - title: string; - boolean?: boolean; - taxonomies?: ITaxonomy[]; + title: string ; + boolean?: boolean | null ; + taxonomies?: ITaxonomy[] | null ; }" - `) - }) -}) + `); + }); +}); From 5062c55803a78dca3fd17dd5c9366682009cff1b Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 29 Nov 2023 17:02:52 +0530 Subject: [PATCH 4/5] adding null only for select, date, file and number --- src/lib/stack/schema.ts | 1 + src/lib/tsgen/factory.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/stack/schema.ts b/src/lib/stack/schema.ts index baa12e0..087a4ba 100644 --- a/src/lib/stack/schema.ts +++ b/src/lib/stack/schema.ts @@ -16,6 +16,7 @@ export type FieldOptions = { multiple: boolean; non_localizable: boolean; max_instance: boolean | undefined; + display_type: string; } & Identifier; export type Block = { diff --git a/src/lib/tsgen/factory.ts b/src/lib/tsgen/factory.ts index 8c0c319..bd07d20 100644 --- a/src/lib/tsgen/factory.ts +++ b/src/lib/tsgen/factory.ts @@ -216,10 +216,11 @@ export default function (userOptions: TSGenOptions) { fieldType += "[]"; } } - + console.log(field.data_type) + console.log(['isodate','file','number'].includes(field.data_type)) return [ field.uid + op_required(field.mandatory) + ':', - fieldType || visit_field_type(field), field.mandatory?'':'| null', ';' + fieldType || visit_field_type(field), (['isodate','file','number'].includes(field.data_type) || ['radio','dropdown'].includes(field.display_type))?field.mandatory?'':'| null':'', ';' ].join(' ') } From e8de39a128b4d37ec5ecd9e51d287df41ec1735d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 29 Nov 2023 17:08:21 +0530 Subject: [PATCH 5/5] test cases fix and removing stray console logs --- src/lib/tsgen/factory.ts | 2 -- tests/tsgen/boolean.test.ts | 2 +- tests/tsgen/global.fields.test.ts | 6 +++--- tests/tsgen/group.test.ts | 18 +++++++++--------- tests/tsgen/jsdoc.test.ts | 4 ++-- tests/tsgen/modular.blocks.test.ts | 14 +++++++------- tests/tsgen/options.test.ts | 6 +++--- tests/tsgen/references.test.ts | 2 +- tests/tsgen/string.test.ts | 8 ++++---- tests/tsgen/taxonomies.test.ts | 4 ++-- 10 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/lib/tsgen/factory.ts b/src/lib/tsgen/factory.ts index bd07d20..cf5355f 100644 --- a/src/lib/tsgen/factory.ts +++ b/src/lib/tsgen/factory.ts @@ -216,8 +216,6 @@ export default function (userOptions: TSGenOptions) { fieldType += "[]"; } } - console.log(field.data_type) - console.log(['isodate','file','number'].includes(field.data_type)) return [ field.uid + op_required(field.mandatory) + ':', fieldType || visit_field_type(field), (['isodate','file','number'].includes(field.data_type) || ['radio','dropdown'].includes(field.display_type))?field.mandatory?'':'| null':'', ';' diff --git a/tests/tsgen/boolean.test.ts b/tests/tsgen/boolean.test.ts index 83810b3..125523d 100644 --- a/tests/tsgen/boolean.test.ts +++ b/tests/tsgen/boolean.test.ts @@ -27,7 +27,7 @@ describe("builtin boolean field", () => { /** Version */ version: 2 ; title: string ; - boolean?: boolean | null ; + boolean?: boolean ; }" `); }); diff --git a/tests/tsgen/global.fields.test.ts b/tests/tsgen/global.fields.test.ts index 128d181..caffbf7 100644 --- a/tests/tsgen/global.fields.test.ts +++ b/tests/tsgen/global.fields.test.ts @@ -26,8 +26,8 @@ describe("global fields", () => { { /** Version */ version: ; - keywords?: string | null ; - description?: string | null ; + keywords?: string ; + description?: string ; }" `); }); @@ -39,7 +39,7 @@ describe("global fields", () => { /** Version */ version: 2 ; title: string ; - seo?: ISeo | null ; + seo?: ISeo ; }" `); }); diff --git a/tests/tsgen/group.test.ts b/tests/tsgen/group.test.ts index d5d9369..7259de0 100644 --- a/tests/tsgen/group.test.ts +++ b/tests/tsgen/group.test.ts @@ -36,20 +36,20 @@ describe("group", () => { number?: number | null ; }, { number?: number | null ; - }] | null ; + }] ; multiple_group?: { - single_line?: string | null ; - }[] | null ; + single_line?: string ; + }[] ; parent_group?: { - rich_text_editor?: string | null ; - multi_line?: string | null ; - single_line?: string | null ; + rich_text_editor?: string ; + multi_line?: string ; + single_line?: string ; child_group?: { number?: number | null ; - boolean?: boolean | null ; + boolean?: boolean ; date?: string | null ; - } | null ; - } | null ; + } ; + } ; }" `); }); diff --git a/tests/tsgen/jsdoc.test.ts b/tests/tsgen/jsdoc.test.ts index 178433a..c5efa75 100644 --- a/tests/tsgen/jsdoc.test.ts +++ b/tests/tsgen/jsdoc.test.ts @@ -22,9 +22,9 @@ describe("jsdoc", () => { /** Age */ current_age?: number | null ; /** City */ - current_city?: string | null ; + current_city?: string ; /** State */ - current_state?: string | null ; + current_state?: string ; }" `); }); diff --git a/tests/tsgen/modular.blocks.test.ts b/tests/tsgen/modular.blocks.test.ts index a77e758..765495d 100644 --- a/tests/tsgen/modular.blocks.test.ts +++ b/tests/tsgen/modular.blocks.test.ts @@ -24,14 +24,14 @@ describe("modular blocks", () => { version: 2 ; title: string ; url: string ; - modular_blocks?: ({string_block: {single_line?: string | null ; - multi_line?: string | null ; - markdown?: string | null ; - rich_text_editor?: string | null ;};string_block_with_options: undefined; + modular_blocks?: ({string_block: {single_line?: string ; + multi_line?: string ; + markdown?: string ; + rich_text_editor?: string ;};string_block_with_options: undefined; boolean_block: undefined;} | {string_block_with_options: {single_line_textbox_required: string ; - single_line_textbox_multiple?: string[] | null ;};string_block: undefined; - boolean_block: undefined;} | {boolean_block: {boolean?: boolean | null ;};string_block: undefined; - string_block_with_options: undefined;})[] | null ; + single_line_textbox_multiple?: string[] ;};string_block: undefined; + boolean_block: undefined;} | {boolean_block: {boolean?: boolean ;};string_block: undefined; + string_block_with_options: undefined;})[] ; }" `); }); diff --git a/tests/tsgen/options.test.ts b/tests/tsgen/options.test.ts index 7b8b609..9466446 100644 --- a/tests/tsgen/options.test.ts +++ b/tests/tsgen/options.test.ts @@ -18,10 +18,10 @@ describe("all options", () => { version: 4 ; title: string ; url: string ; - single_line_textbox_not_required?: string | null ; + single_line_textbox_not_required?: string ; single_line_textbox_required: string ; - single_line_textbox_multiple?: string[] | null ; - single_line_textbox_multiple_max_limit?: [string, string, string, string, string] | null ; + single_line_textbox_multiple?: string[] ; + single_line_textbox_multiple_max_limit?: [string, string, string, string, string] ; }" `); }); diff --git a/tests/tsgen/references.test.ts b/tests/tsgen/references.test.ts index c0e1f9d..2ef381e 100644 --- a/tests/tsgen/references.test.ts +++ b/tests/tsgen/references.test.ts @@ -30,7 +30,7 @@ describe("references", () => { title: string ; url: string ; single_reference: (IReferenceChild) ; - multiple_reference?: (IReferenceChild | IBoolean | IBuiltinExample)[] | null ; + multiple_reference?: (IReferenceChild | IBoolean | IBuiltinExample)[] ; }" `); }); diff --git a/tests/tsgen/string.test.ts b/tests/tsgen/string.test.ts index 3005d41..00ba136 100644 --- a/tests/tsgen/string.test.ts +++ b/tests/tsgen/string.test.ts @@ -24,10 +24,10 @@ describe("builtin string fields", () => { /** Version */ version: 4 ; title: string ; - single_line?: string | null ; - multi_line?: string | null ; - rich_text_editor?: string | null ; - markdown?: string | null ; + single_line?: string ; + multi_line?: string ; + rich_text_editor?: string ; + markdown?: string ; }" `); }); diff --git a/tests/tsgen/taxonomies.test.ts b/tests/tsgen/taxonomies.test.ts index 6e5f87c..6ae0414 100644 --- a/tests/tsgen/taxonomies.test.ts +++ b/tests/tsgen/taxonomies.test.ts @@ -29,8 +29,8 @@ describe("builtin taxonomies field", () => { /** Version */ version: 2 ; title: string ; - boolean?: boolean | null ; - taxonomies?: ITaxonomy[] | null ; + boolean?: boolean ; + taxonomies?: ITaxonomy[] ; }" `); });