contentstack / contentstack-cli-tsgen Goto Github PK
View Code? Open in Web Editor NEWGenerate TypeScript typings from a Stack
License: MIT License
Generate TypeScript typings from a Stack
License: MIT License
If you fetch entries via SDK or API it sends entries with additional data like UID, created_at, publish_details fields, and so on. But the TSGen plugin doesn't add this information when you generate types.
CS always sends references as an array of entries. It means that all references must be like arrays, and empty arrays in case if reference is not specified. Even if this field is not mandatory, it will be an empty array.
{
someEntryReference: EntryModel[]
}
But for some reason TSGen gives you:
{
someEntryReference?: EntryModel
}
Looks like a bug or not documented behavior.
Hi, I just tried to use the package, but it failed with the following output:
% csdx tsgen -a "test" -o "test.d.ts"
SyntaxError: Declaration or statement expected. (3111:1)
3109 | }
3110 |
> 3111 | export interface 1Feature
| ^
3112 | {
3113 | /** Version */
3114 | version: 4 ;
I'm using CLI v1.9.1 with tsgen v2.1.7 - all freshly installed today.
The credentials do work, by the way. Before I got this error message, I used wrong credentials and received the respective credential error.
I have a content model with two non-mandatory fields of type Date and Select. The tsgen plugin exports this content model as follows:
export interface TestModel {
title: string;
date?: string;
select?: "lorem" | "ipsum";
}
However, this is what is actually sent from the API with the two non-optional fields left empty (generic fields removed from output):
{
"date": null,
"select": null,
"title": "Test TSGen",
}
This causes a TS error: Type 'null' is not assignable to type 'string | undefined'
.
I have double checked all the api keys and region, but it is unable to connect to my stack.
Currently using EU region
Error: Could not connect to the stack. Please check your credentials.
After the release of 2.3.0
it broke our codegen as grapql
is missing even though we're not using GraphQL.
(node:25983) [MODULE_NOT_FOUND] ModuleLoadError Plugin: contentstack-cli-tsgen: [MODULE_NOT_FOUND] require failed to load /Users/user/.local/share/@contentstack/cli/node_modules/contentstack-cli-tsgen/lib/commands/tsgen.js: Cannot find module 'graphql'
Hello,
thank you for creating this fantastic package. We've recently begun using it, and it has significantly improved our contentstack typing.
One observation we've made is that every extension/custom field currently returns the type any
. Is there a possibility to implement typing for these cases too? In most instances, we know the types returned by various extensions, at least in about 99% of the cases.
❯ csdx tsgen -a "delivery-token" -o "./contenstack/generated.d.ts"
Currently using NA region
SyntaxError: '=>' expected. (38:16)
36 | title: string;
37 | /** Image Block /
> 38 | image_block: ()[];
| ^
39 | /* Banner Title /
40 | banner_title?: string;
41 | /* Banner Description */
This is the output of my tsgen. It stop working on image_block because of this non-speaking error.
A referenced field that is not set as "multiple" has the type generated as an array.
Example from the demo data (from the starters): a header object has a reference to a page - page_reference
. It looks like this
{
"data_type": "reference",
"display_name": "Page Reference",
"reference_to": [
"page"
],
"field_metadata": {
"ref_multiple": false,
"ref_multiple_content_types": true,
"description": "Refers a linked entity of type page",
"instruction": "Refers a linked entity of type page"
},
"uid": "page_reference",
"non_localizable": false,
"mandatory": false,
"multiple": false,
"unique": false
}
However, the generated type looks like this:
navigation_menu?: [
{
/** Label */
label?: string;
/** Page Reference */
page_reference?: Page[]; // <--- should not be an array unless "multiple" is set to "true"
},
]
I tried changing it to multiple and back to single, but nothing changes with regards to the generated type.
Version:
❯ csdx plugins
contentstack-cli-tsgen 2.1.6
Hi!
I'm trying to generate types for the Stack, but when I run the tsgen it returns the following Syntax error:
SyntaxError: '=>' expected.
reference: ()[];
| ^
Let me know if you need more information!
$ csdx tsgen -a "Token" -o "contentstack/generated.d.ts"
TypeError: Cannot read properties of undefined (reading 'token-alias')
Tried with both Delivery and Management tokens
Was working a few weeks back but I got a new machine and started getting this error, not sure if it was a new update in the meantime.
@contentstack/cli/1.3.0 win32-x64 node-v16.14.1
NPM 9.1.1
contentstack-cli-tsgen 1.0.13
Thanks in advance
WARNING! Obsolete function called. Function 'Contentstack.Stack(api_key, delivery_token, environment)' has been deprecated, please use 'Contentstack.Stack({api_key, delivery_token, environment, region, branch, fetchOptions})' function instead!
Content stack appends Connection after all field names that are references, and also adds subfields in GraphQL.
example:
Content type field:
Reference to ContentBelt type
GraphQL request response:
"content_beltsConnection": { "edges": [ { "node": { "title": "Collapsibles test", "system": { "uid": "blt847f4e37080902a8" } } },] }
however the tsgen result of that is just the field name, with an array of the content type:
navigation_menu: ContentBelt[]
In the last version of contentstack-cli-tsgen
The file __generated__.types.ts
includes the field version
on the global fields interfaces
why you added version
to global fields? is this intended?
I've resolved that when I've installed a previous version
csdx plugins:install [email protected]
It would be very useful to be able to include things like _content_type_uid
and _version
, etc. in the generated typings, but this is not possible currently.
I am unable to run csdx tsgen. I am getting an Error: "Token not found" although I included a created token alias. Could you help me with this, please?
➜ ~ csdx tsgen -a "my-token" -o "generated.d.ts"
Currently using NA region
Error: Token not found
I created my-token-alias with
csdx auth:tokens
So running csdx auth:tokens I can see
Alias Token Apikey Environment Type
───────────────────────────────────────────────────────────────────────────────────────
my-token <mytoken> <my API key> production delivery
Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.