diff --git a/package-lock.json b/package-lock.json index f816be8..d27d955 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "contentstack-cli-tsgen", - "version": "2.1.8", + "version": "2.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack-cli-tsgen", - "version": "2.1.8", + "version": "2.2.0", "license": "MIT", "dependencies": { - "@contentstack/cli-command": "^1.2.9", - "@contentstack/cli-utilities": "^1.4.5", + "@contentstack/cli-command": "^1.2.13", + "@contentstack/cli-utilities": "^1.5.2", "lodash": "^4.17.20", "prettier": "^2.0.5", "tslib": "^1.13.0" @@ -621,19 +621,19 @@ } }, "node_modules/@colors/colors": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", - "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.6.0.tgz", + "integrity": "sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==", "engines": { "node": ">=0.1.90" } }, "node_modules/@contentstack/cli-command": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/@contentstack/cli-command/-/cli-command-1.2.9.tgz", - "integrity": "sha512-kmAIWUtEib6VnME2A2RN/ltLrVzaijgvczbMFQoFJZBvHkyZQ8yn+406EY1sq/DB8vGuHYRz+4RMIZ8G8y034g==", + "version": "1.2.13", + "resolved": "https://registry.npmjs.org/@contentstack/cli-command/-/cli-command-1.2.13.tgz", + "integrity": "sha512-T01EtJI5hpYIIHdZcrx5faPsBrE1PwIgZz6onx+W9XCV8Or+HIeg1iUojk+CiehpYe2CVOoiAbL1KYnQtVGA6A==", "dependencies": { - "@contentstack/cli-utilities": "^1.4.5", + "@contentstack/cli-utilities": "~1.5.3", "contentstack": "^3.10.1" }, "engines": { @@ -641,12 +641,12 @@ } }, "node_modules/@contentstack/cli-utilities": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/@contentstack/cli-utilities/-/cli-utilities-1.4.5.tgz", - "integrity": "sha512-rAOHX6ZKfBfdRA0VtIrs3a2QOZIq3yIlNSLY0cqksRDvqvnsUa0wwyKjew2pvDkP4tVXOrVm5S5rjwW7a74MIw==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@contentstack/cli-utilities/-/cli-utilities-1.5.3.tgz", + "integrity": "sha512-c5iv9o0rOYdNN3rlQd2hOoQHIqpoU2MqM/jWYzqtjH1MttJsf/SaEs1Zjb5hO1FHHuhznEXpPQHM4PBZ5BsMJA==", "dependencies": { - "@contentstack/management": "^1.8.0", - "@oclif/core": "^2.8.2", + "@contentstack/management": "~1.10.2", + "@oclif/core": "^2.9.3", "axios": "1.3.4", "chalk": "^4.0.0", "cli-cursor": "^3.1.0", @@ -658,6 +658,7 @@ "inquirer-search-checkbox": "^1.0.0", "inquirer-search-list": "^1.2.6", "lodash": "^4.17.15", + "mkdirp": "^1.0.4", "open": "^8.4.2", "ora": "^5.4.0", "rxjs": "^6.6.7", @@ -667,6 +668,17 @@ "xdg-basedir": "^4.0.0" } }, + "node_modules/@contentstack/cli-utilities/node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@contentstack/cli-utilities/node_modules/rxjs": { "version": "6.6.7", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", @@ -679,26 +691,27 @@ } }, "node_modules/@contentstack/management": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.8.0.tgz", - "integrity": "sha512-rKI9CEwwmh8L0f5OaicjBlty0O77BT3KiHkPj23rJ2lLWlas7RlWaVhbavXJASSpS0w1FWx8+BmGwkaAoRVyRg==", + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.10.2.tgz", + "integrity": "sha512-jO24EqcCJhOjqdsqw8y3T0SPPAd0DG4BByjUcV0S28W2yoa8aBbcjcbZioRPzRLYKTmZWsAZissl18cIJm5djQ==", "dependencies": { - "axios": "^0.27.2", + "axios": "^1.4.0", "form-data": "^3.0.1", "lodash": "^4.17.21", - "qs": "^6.10.3" + "qs": "^6.11.2" }, "engines": { "node": ">=8.0.0" } }, "node_modules/@contentstack/management/node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", + "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.14.9", - "form-data": "^4.0.0" + "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": { @@ -1666,9 +1679,9 @@ "dev": true }, "node_modules/@oclif/core": { - "version": "2.8.10", - "resolved": "https://registry.npmjs.org/@oclif/core/-/core-2.8.10.tgz", - "integrity": "sha512-coRn9vYDEnoE8Vg20aavts9+Bt5QrHhbdh0cDkImopV0MgT8i/VmgL04D33+qoHQH20XzBOMqrjk+bqQzqyaHg==", + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/@oclif/core/-/core-2.15.0.tgz", + "integrity": "sha512-fNEMG5DzJHhYmI3MgpByTvltBOMyFcnRIUMxbiz2ai8rhaYgaTHMG3Q38HcosfIvtw9nCjxpcQtC8MN8QtVCcA==", "dependencies": { "@types/cli-progress": "^3.11.0", "ansi-escapes": "^4.3.2", @@ -1679,7 +1692,6 @@ "cli-progress": "^3.12.0", "debug": "^4.3.4", "ejs": "^3.1.8", - "fs-extra": "^9.1.0", "get-package-type": "^0.1.0", "globby": "^11.1.0", "hyperlinker": "^1.0.0", @@ -1689,7 +1701,7 @@ "natural-orderby": "^2.0.3", "object-treeify": "^1.1.33", "password-prompt": "^1.1.2", - "semver": "^7.3.7", + "slice-ansi": "^4.0.0", "string-width": "^4.2.3", "strip-ansi": "^6.0.1", "supports-color": "^8.1.1", @@ -1704,6 +1716,14 @@ "node": ">=14.0.0" } }, + "node_modules/@oclif/core/node_modules/astral-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", + "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/@oclif/core/node_modules/globby": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", @@ -1731,6 +1751,22 @@ "node": ">= 4" } }, + "node_modules/@oclif/core/node_modules/slice-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", + "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", + "dependencies": { + "ansi-styles": "^4.0.0", + "astral-regex": "^2.0.0", + "is-fullwidth-code-point": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/slice-ansi?sponsor=1" + } + }, "node_modules/@oclif/core/node_modules/tslib": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", @@ -2785,9 +2821,9 @@ "dev": true }, "node_modules/@types/triple-beam": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.2.tgz", - "integrity": "sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g==" + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.3.tgz", + "integrity": "sha512-6tOUG+nVHn0cJbVp25JFayS5UE6+xlbcNF9Lo9mU7U0zk3zeUShZied4YEQZjy1JBF043FSkdXw8YkUJuVtB5g==" }, "node_modules/@types/vinyl": { "version": "2.0.7", @@ -3287,6 +3323,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", + "dev": true, "engines": { "node": ">= 4.0.0" } @@ -6354,9 +6391,9 @@ "integrity": "sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==" }, "node_modules/follow-redirects": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz", - "integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==", + "version": "1.15.3", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", + "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", "funding": [ { "type": "individual", @@ -6506,6 +6543,7 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "dev": true, "dependencies": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", @@ -6788,7 +6826,8 @@ "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true }, "node_modules/grouped-queue": { "version": "2.0.0", @@ -8902,6 +8941,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, "dependencies": { "universalify": "^2.0.0" }, @@ -9100,16 +9140,19 @@ } }, "node_modules/logform": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/logform/-/logform-2.5.1.tgz", - "integrity": "sha512-9FyqAm9o9NKKfiAKfZoYo9bGXXuwMkxQiQttkT4YjjVtQVIQtK6LmVtlxmCaFswo6N4AfEkHqZTV0taDtPotNg==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-2.6.0.tgz", + "integrity": "sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ==", "dependencies": { - "@colors/colors": "1.5.0", + "@colors/colors": "1.6.0", "@types/triple-beam": "^1.3.2", "fecha": "^4.2.0", "ms": "^2.1.1", "safe-stable-stringify": "^2.3.1", "triple-beam": "^1.3.0" + }, + "engines": { + "node": ">= 12.0.0" } }, "node_modules/lowercase-keys": { @@ -11348,9 +11391,9 @@ } }, "node_modules/qs": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.1.tgz", - "integrity": "sha512-0wsrzgTz/kAVIeuxSjnpGC56rzYtr6JT/2BwEvMaPhFIoYa1aGO8LbzuU1R0uUYQkLpWBTOj0l/CLAJB64J6nQ==", + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", "dependencies": { "side-channel": "^1.0.4" }, @@ -13766,9 +13809,12 @@ "dev": true }, "node_modules/triple-beam": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", - "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", + "integrity": "sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==", + "engines": { + "node": ">= 14.0.0" + } }, "node_modules/ts-jest": { "version": "26.5.6", @@ -14260,6 +14306,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "dev": true, "engines": { "node": ">= 10.0.0" } @@ -14416,9 +14463,13 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/uuid": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", - "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } @@ -14671,11 +14722,11 @@ } }, "node_modules/winston": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.9.0.tgz", - "integrity": "sha512-jW51iW/X95BCW6MMtZWr2jKQBP4hV5bIDq9QrIjfDk6Q9QuxvTKEAlpUNAzP+HYHFFCeENhph16s0zEunu4uuQ==", + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.11.0.tgz", + "integrity": "sha512-L3yR6/MzZAOl0DsysUXHVjOwv8mKZ71TrA/41EIduGpOOV5LQVodqN+QdQ6BS6PJ/RdIshZhq84P/fStEZkk7g==", "dependencies": { - "@colors/colors": "1.5.0", + "@colors/colors": "^1.6.0", "@dabh/diagnostics": "^2.0.2", "async": "^3.2.3", "is-stream": "^2.0.0", @@ -14692,16 +14743,16 @@ } }, "node_modules/winston-transport": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.5.0.tgz", - "integrity": "sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==", + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.6.0.tgz", + "integrity": "sha512-wbBA9PbPAHxKiygo7ub7BYRiKxms0tpfU2ljtWzb3SjRjv5yl6Ozuy/TkXf00HTAt+Uylo3gSkNwzc4ME0wiIg==", "dependencies": { "logform": "^2.3.2", "readable-stream": "^3.6.0", "triple-beam": "^1.3.0" }, "engines": { - "node": ">= 6.4.0" + "node": ">= 12.0.0" } }, "node_modules/word-wrap": { diff --git a/package.json b/package.json index d9892fb..edd1b51 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "contentstack-cli-tsgen", "description": "Generate TypeScript typings from a Stack.", - "version": "2.1.8", + "version": "2.2.0", "author": "Michael Davis", "bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues", "dependencies": { - "@contentstack/cli-command": "^1.2.9", - "@contentstack/cli-utilities": "^1.4.5", + "@contentstack/cli-command": "^1.2.13", + "@contentstack/cli-utilities": "^1.5.2", "lodash": "^4.17.20", "prettier": "^2.0.5", "tslib": "^1.13.0" diff --git a/src/commands/tsgen.ts b/src/commands/tsgen.ts index 94f6aa9..dd40330 100644 --- a/src/commands/tsgen.ts +++ b/src/commands/tsgen.ts @@ -85,7 +85,7 @@ export default class TypeScriptCodeGeneratorCommand extends Command { branch: branch || null, } - const [client, globalFields] = await Promise.all([stackConnect(this.deliveryAPIClient.Stack, config), getGlobalFields(config)]) + const [client, globalFields] = await Promise.all([stackConnect(this.deliveryAPIClient.Stack, config, this.cdaHost), getGlobalFields(config, this.cdaHost)]) let schemas: ContentType[] = [] if (client.types?.length) { diff --git a/src/lib/stack/builtins.ts b/src/lib/stack/builtins.ts index 902aa88..98a8b9b 100644 --- a/src/lib/stack/builtins.ts +++ b/src/lib/stack/builtins.ts @@ -28,7 +28,13 @@ export const defaultInterfaces = (prefix = '', systemFields = false) => { `export interface ${prefix}Link { title: string; href: string; - }` + }`, + `export interface ${prefix}Taxonomy { + taxonomy_uid: string; + max_terms?: number; + mandatory: boolean; + non_localizable: boolean; + }` ] if (systemFields) { defaultInterfaces.push( diff --git a/src/lib/stack/client.ts b/src/lib/stack/client.ts index 570fa7a..5a20cc8 100644 --- a/src/lib/stack/client.ts +++ b/src/lib/stack/client.ts @@ -11,7 +11,7 @@ const REGION_URL_MAPPING: RegionUrlMap = { us: 'cdn.contentstack.io', eu: 'eu-cdn.contentstack.com', 'azure-na': 'azure-na-cdn.contentstack.com', - 'azure-eu': 'azure-eu-cdn.contentstack.com', + 'azure-eu': 'azure-eu-cdn.contentstack.com' } export type StackConnectionConfig = { @@ -29,7 +29,7 @@ const queryParams = { include_global_field_schema: true, } -export async function stackConnect(client: any, config: StackConnectionConfig) { +export async function stackConnect(client: any, config: StackConnectionConfig, cdaHost: string) { try { const clientParams: { api_key: string, @@ -48,6 +48,10 @@ export async function stackConnect(client: any, config: StackConnectionConfig) { } // eslint-disable-next-line new-cap const stack = client(clientParams) + // check and update host if doesn't exists in REGION_URL_MAPPING + if (!REGION_URL_MAPPING[clientParams.region]) { + stack.setHost(cdaHost) + } const results = (await stack.getContentTypes({ ...queryParams, @@ -95,11 +99,11 @@ export async function stackConnect(client: any, config: StackConnectionConfig) { } // Currently delivery sdk does not support querying global fields on a stack. Hence direct call is required. -export async function getGlobalFields(config: StackConnectionConfig) { +export async function getGlobalFields(config: StackConnectionConfig, cdaHost: string) { try { return new Promise((resolve, reject) => { const options: any = { - host: (REGION_URL_MAPPING as any)[config.region], + host: (REGION_URL_MAPPING as any)[config.region] || cdaHost, path: 'v3/global_fields?include_branch=false', port: 443, method: 'GET', diff --git a/src/lib/tsgen/factory.ts b/src/lib/tsgen/factory.ts index f90a63d..e93a230 100644 --- a/src/lib/tsgen/factory.ts +++ b/src/lib/tsgen/factory.ts @@ -85,6 +85,11 @@ export default function (userOptions: TSGenOptions) { track: true, flag: TypeFlags.UserReference, }, + taxonomy: { + func: type_taxonomy, + track: true, + flag: TypeFlags.BuiltinCS, + }, } function track_dependency(field: ContentstackTypes.Field, type: string, flag: TypeFlags) { @@ -341,4 +346,8 @@ export default function (userOptions: TSGenOptions) { }, } } + + function type_taxonomy() { + return `${options?.naming?.prefix}Taxonomy` + } } diff --git a/tests/tsgen/taxonomies.ct.js b/tests/tsgen/taxonomies.ct.js new file mode 100644 index 0000000..c997772 --- /dev/null +++ b/tests/tsgen/taxonomies.ct.js @@ -0,0 +1,150 @@ +const builtinTaxonomies = { + created_at: '2020-07-12T14:36:50.167Z', + updated_at: '2020-07-12T14:37:02.250Z', + title: 'Taxonomies', + uid: 'taxonomy', + _version: 2, + inbuilt_class: false, + schema: [ + { + display_name: 'Title', + uid: 'title', + data_type: 'text', + mandatory: true, + unique: true, + field_metadata: { + _default: true, + version: 3, + }, + multiple: false, + non_localizable: false, + }, + { + data_type: 'boolean', + display_name: 'Boolean', + uid: 'boolean', + field_metadata: { + description: '', + default_value: '', + }, + multiple: false, + mandatory: false, + unique: false, + non_localizable: false, + }, + { + data_type: 'taxonomy', + display_name: 'Taxonomy', + uid: 'taxonomies', + taxonomies: [ + { + taxonomy_uid: 'taxonomy1', + max_terms: 2, + mandatory: true, + non_localizable: false, + }, + { + taxonomy_uid: 'taxonomy2', + max_terms: 2, + mandatory: true, + non_localizable: false, + }, + ], + field_metadata: {description: '', default_value: ''}, + format: '', + mandatory: false, + multiple: true, + non_localizable: false, + unique: false, + schema: [], + }, + ], + last_activity: {}, + maintain_revisions: true, + description: '', + DEFAULT_ACL: { + others: { + read: false, + create: false, + }, + users: [ + { + uid: 'user1', + read: true, + sub_acl: { + read: true, + }, + }, + ], + }, + SYS_ACL: { + roles: [ + { + uid: 'role1', + read: true, + sub_acl: { + create: true, + read: true, + update: true, + delete: true, + publish: true, + }, + update: true, + delete: true, + }, + { + uid: 'role2', + read: true, + sub_acl: { + create: true, + read: true, + update: true, + delete: true, + publish: true, + }, + }, + { + uid: 'role3', + read: true, + sub_acl: { + create: true, + read: true, + update: true, + delete: true, + publish: true, + }, + update: true, + delete: true, + }, + ], + others: { + read: false, + create: false, + update: false, + delete: false, + sub_acl: { + read: false, + create: false, + update: false, + delete: false, + publish: false, + }, + }, + }, + options: { + is_page: false, + singleton: true, + title: 'title', + sub_title: [], + }, + abilities: { + get_one_object: true, + get_all_objects: true, + create_object: true, + update_object: true, + delete_object: true, + delete_all_objects: true, + }, +} + +module.exports = {builtinTaxonomies} diff --git a/tests/tsgen/taxonomies.test.ts b/tests/tsgen/taxonomies.test.ts new file mode 100644 index 0000000..9f3812d --- /dev/null +++ b/tests/tsgen/taxonomies.test.ts @@ -0,0 +1,36 @@ +const testData = require('./taxonomies.ct') + +import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc' +import tsgenFactory from '../../src/lib/tsgen/factory' + +const tsgen = tsgenFactory({ + docgen: new NullDocumentationGenerator(), + naming: { + prefix: 'I', + }, +}) + +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('definition', () => { + expect(result.definition).toMatchInlineSnapshot(` + "export interface ITaxonomy + { + /** Version */ + version: 2 ; + title: string; + boolean?: boolean; + taxonomies?: ITaxonomy[]; + }" + `) + }) +})