From 3690d00a8dfe307cfe2dff204172198db4d315ec Mon Sep 17 00:00:00 2001 From: naman-contentstack Date: Mon, 23 Dec 2024 12:38:13 +0530 Subject: [PATCH] fixed mismatched typings --- src/generateTS/factory.ts | 11 ++++++++--- src/generateTS/index.ts | 17 +++++++++++++++++ src/generateTS/stack/builtins.ts | 3 ++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/generateTS/factory.ts b/src/generateTS/factory.ts index 65a7790..292e921 100644 --- a/src/generateTS/factory.ts +++ b/src/generateTS/factory.ts @@ -261,7 +261,7 @@ export default function (userOptions: TSGenOptions) { define_interface(contentType, options.systemFields), "{", ["/**", "Version", "*/"].join(" "), - [`_version: `, contentType._version, ";"].join(" "), + `_version: number;`, visit_fields(contentType.schema), "}", ] @@ -328,8 +328,13 @@ export default function (userOptions: TSGenOptions) { return `${options.naming?.prefix}Link`; } - function type_file() { - return `${options.naming?.prefix}File`; + function type_file(field: ContentstackTypes.Field): string { + // Check if the field is `parent_uid` + if (field.uid === "parent_uid") { + return "string | null"; // Explicitly handle `parent_uid` + } + // Default handling for other file-related fields + return "string"; // Or any other default structure } function type_global_field(field: ContentstackTypes.GlobalField) { diff --git a/src/generateTS/index.ts b/src/generateTS/index.ts index b38d2cf..342762c 100644 --- a/src/generateTS/index.ts +++ b/src/generateTS/index.ts @@ -161,3 +161,20 @@ export const generateTSFromContentTypes = async ({ }; } }; + +// const fun = async () => { +// const config: GenerateTSBase = { +// apiKey: "blt90b7f961dd6ed75e", +// token: "cs8dadf8eec9a363f2a3aaf809", +// region: "US", +// environment: "local", +// branch: undefined, +// host: "cdn.contentstack.io", +// tokenType: "delivery", +// includeDocumentation: true, +// systemFields: false, +// }; + +// return await generateTS(config); +// }; +// console.log("🚀 ~ result:", fun()); diff --git a/src/generateTS/stack/builtins.ts b/src/generateTS/stack/builtins.ts index d45d041..462426b 100644 --- a/src/generateTS/stack/builtins.ts +++ b/src/generateTS/stack/builtins.ts @@ -17,11 +17,12 @@ export const defaultInterfaces = (prefix = "", systemFields = false) => { tags: string[]; filename: string; url: string; - ACL: any[]; + ACL: any[] | object; is_dir: boolean; parent_uid: string; _version: number; title: string; + _metadata?:object; publish_details: ${prefix}PublishDetails; }`, `export interface ${prefix}Link {