Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernization & support for migration / items models #61

Open
wants to merge 184 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
184 commits
Select commit Hold shift + click to select a range
9aee071
Refactors CLI setup, uses chalk instead of colors, updates tsconfig/e…
Enngage Jul 22, 2024
3f04f57
Prepares test scripts & utils, renames `sdkType` to `modelType`, remo…
Enngage Jul 22, 2024
00e8226
Adds support for generating base migration types
Enngage Jul 24, 2024
fd52b1e
prepares new fileProcessor closure with output dir support
Enngage Jul 24, 2024
7a915af
Adds support for generating MigrationItem models
Enngage Jul 25, 2024
480a9d1
Adds migration Item export type
Enngage Jul 25, 2024
6b85ed2
Adds moduleResolution support to migration generator
Enngage Jul 25, 2024
45f4e13
imports only types
Enngage Jul 25, 2024
272a4b7
Adds migration related props readonly
Enngage Jul 25, 2024
3464c98
Merge branch 'master' into modernization-and-migration-support
Enngage Aug 15, 2024
7471be2
updates deps
Enngage Aug 15, 2024
65577bb
updates deps
Enngage Aug 19, 2024
ab968fc
updates code samples
Enngage Aug 19, 2024
48b135e
updates deps, adds ts-pattern, adds comments to migration models
Enngage Aug 19, 2024
3e1c145
Implements migration action and separates it from main generator
Enngage Aug 19, 2024
a28ec19
feat!: Separates Delivery & Project models
Enngage Aug 19, 2024
5f69ea2
Makes project models readonly
Enngage Aug 19, 2024
8c9bb6e
Adds readonly modifiers to remaining migration input props
Enngage Aug 20, 2024
2f129cc
Refactors project generator
Enngage Aug 20, 2024
26f1bd0
Updates imports
Enngage Aug 20, 2024
b7f0923
Delete index.ts
Enngage Aug 21, 2024
635fe43
removes baseUrl tsconfig.json option, updates paths
Enngage Aug 21, 2024
764b593
Fixes output dir for project generator
Enngage Aug 21, 2024
358278a
Improves file creation, removes sort config
Enngage Aug 21, 2024
ecf995c
adds readonly modifiers
Enngage Aug 21, 2024
ce3f22b
refactors delivery func, removes FIleHelper, updates file imports
Enngage Aug 21, 2024
72207c7
refactors taxonomy generator
Enngage Aug 22, 2024
424ff7d
Delivery generator refactor #1
Enngage Aug 22, 2024
94cf57b
Refactors content type imports, extends flattened element with snippe…
Enngage Aug 27, 2024
a195250
refactors delivery file name resolvers, removes name/text helpers, si…
Enngage Aug 28, 2024
5aee75c
Completes resolvers refactoring, renames file processor, improves del…
Enngage Aug 29, 2024
ce3a64a
Refactors format helper
Enngage Aug 29, 2024
bc5de59
Removes models file
Enngage Aug 29, 2024
a0dd8b1
Removes delivery mappers
Enngage Aug 29, 2024
679047d
Unifies and simplifies generator functions
Enngage Aug 29, 2024
95733e0
Unifies default module resolution
Enngage Aug 29, 2024
4f921db
Adds autogenerated note with environment info to every file
Enngage Aug 29, 2024
2db3796
Updates samples
Enngage Aug 29, 2024
964ae00
fixes incorrect referenced types folder
Enngage Aug 29, 2024
140d5d9
Adds project to environment info comment
Enngage Aug 29, 2024
f8c406b
increases print width
Enngage Aug 29, 2024
40bf061
Update resolvers.ts
Enngage Aug 29, 2024
7ea0eae
Adds missing readonly modifiers, updates printWidth
Enngage Aug 29, 2024
63c8e94
Further code refactorings
Enngage Sep 2, 2024
14edc88
Separates migration - environment types into own file / folder
Enngage Sep 2, 2024
c6ee50c
Extends delivery config
Enngage Sep 2, 2024
cfa66d5
Unifies filename extraction
Enngage Sep 2, 2024
1e2af7d
Removes unused code, minor improvements
Enngage Sep 2, 2024
087e6cf
updates deps
Enngage Sep 2, 2024
ee9480c
Organizes imports
Enngage Sep 3, 2024
7fc9a71
removes exitProgram func
Enngage Sep 3, 2024
45fea6e
Adds sorting to fetched items / elements
Enngage Sep 3, 2024
0b4a5c9
removes comments manager
Enngage Sep 3, 2024
34ef29c
Loads kontent.ai items in paralel
Enngage Sep 3, 2024
fc9ec58
Update project-func.ts
Enngage Sep 3, 2024
7013249
Update migration-func.ts
Enngage Sep 3, 2024
4aa21ed
Adds sort
Enngage Sep 3, 2024
2ebb795
Updates CLI actions, uses pattern match for action input
Enngage Sep 3, 2024
b80ea24
Uses pattern match for cli app
Enngage Sep 3, 2024
df8b8fe
Renames project action to environment
Enngage Sep 3, 2024
2442fe6
Sets up commands & options
Enngage Sep 3, 2024
6839f0e
typo
Enngage Sep 3, 2024
8bc87a1
Use top level await
Enngage Sep 3, 2024
6af41cd
Updates readme
Enngage Sep 3, 2024
dbf0693
Updates project -> environment sample
Enngage Sep 3, 2024
217b735
Update README.md
Enngage Sep 3, 2024
1c9d2ca
Update LICENSE.md
Enngage Sep 3, 2024
2e8c08d
updates deps
Enngage Sep 4, 2024
20ae242
Simplifies version script, uses top-level await for sample codes
Enngage Sep 4, 2024
437f6ae
Sample codes
Enngage Sep 4, 2024
d526138
Update main.yml
Enngage Sep 4, 2024
2e71109
Update package.json
Enngage Sep 4, 2024
971d077
Use name prop for resolving names instead of codename
Enngage Sep 4, 2024
9706c25
Moves barrel export function to importer
Enngage Sep 4, 2024
488721d
Unifies comments wrapping & allow more special characters inside
Enngage Sep 4, 2024
0d46b24
Use safe property name / value processor, updates samples
Enngage Sep 4, 2024
9739753
Preserves order of items fetched from API (fixes https://github.com/k…
Enngage Sep 4, 2024
023cd8d
Adds support for generating item codenames type & ids/codename obj (f…
Enngage Sep 9, 2024
22de18e
Updates deps, upgrades to beta version of delivery-sdk & removes elem…
Enngage Sep 10, 2024
824e167
Updades migration comments
Enngage Sep 10, 2024
90d6c33
Unifies model func
Enngage Sep 10, 2024
cbc578e
Extends IContentItem with type string literal, fixes subpages element…
Enngage Sep 11, 2024
77007f2
Fixes toSafePropertyName func
Enngage Sep 11, 2024
3625488
Implements types support for delivery item system attributes, updates…
Enngage Sep 11, 2024
ecb07f3
Adds readonly modifier to migration / delivery elements, adds own lin…
Enngage Sep 11, 2024
46e0b96
Adds codename of taxonomy to Delivery taxonomy elements
Enngage Sep 11, 2024
b9da5d5
Adds delivery element typing for multiple choice codenames
Enngage Sep 11, 2024
13b49c8
Handle cases where allowed linked items are not defined, adds allowed…
Enngage Sep 11, 2024
a56bf5f
Update element.utils.ts
Enngage Sep 11, 2024
94637fe
Use named input props for getFlattenedElements
Enngage Sep 11, 2024
98bca09
Minor improvements
Enngage Sep 11, 2024
75c5b7b
Update migration.generator.ts
Enngage Sep 11, 2024
1dcf824
Removes barrel files, specifically define Public API with named exports
Enngage Sep 12, 2024
ab117d9
Update config.ts
Enngage Sep 12, 2024
407c9e6
Use config value for barrel export filename
Enngage Sep 12, 2024
bd05c16
updates deps
Enngage Sep 16, 2024
9bea623
chore(release): 8.0.0-0
Enngage Sep 16, 2024
183ab24
Update metadata.ts
Enngage Sep 16, 2024
f8871a5
Fixes update version script
Enngage Sep 16, 2024
3b92689
fix: Adds missing references for RichTextElement
Enngage Sep 16, 2024
8e01505
chore(release): 8.0.0-1
Enngage Sep 16, 2024
1f177de
chore(release): 8.0.0-2
Enngage Sep 16, 2024
a537a8d
updates deps & moves delivery-sdk/migration-toolkit to dev deps
Enngage Sep 26, 2024
a00dbee
updates deps
Enngage Sep 27, 2024
4a8ce44
Generates codenames of type / snippet elements & uses 'Snippet' type …
Enngage Sep 27, 2024
94d245d
Use safe property name for language codename as it may contain "non-c…
Enngage Sep 27, 2024
6885d76
fixes https://github.com/kontent-ai/model-generator-js/pull/61#pullre…
Enngage Sep 27, 2024
02cfa46
Use satisfies in args & sets up CliAction generic argument
Enngage Sep 27, 2024
c3ddaa6
Update core.utils.ts
Enngage Sep 27, 2024
4a26d1b
Make param required
Enngage Sep 27, 2024
b7dcec4
removes "m" modifier
Enngage Sep 27, 2024
168ee14
Use ts-pattern to match is_required
Enngage Sep 27, 2024
c44b51d
Rename handleError, convert to local function
Enngage Sep 27, 2024
12e6b23
Simplify management client creation
Enngage Sep 27, 2024
ed01390
Uses local impl of isNotUnefined
Enngage Sep 27, 2024
c05b7b2
Use ts-pattern for matching element guidelines
Enngage Sep 27, 2024
77483bf
Cleans up eslint deps
Enngage Sep 27, 2024
6701467
Update package.json
Enngage Sep 27, 2024
d3cfee8
Use ts-pattern instead of type casting
Enngage Sep 27, 2024
81f7db9
Use local eslint in lint scripts
Enngage Sep 27, 2024
681e49d
Tries lts as node-version
Enngage Sep 27, 2024
26fc145
Update main.yml
Enngage Sep 27, 2024
e921a94
Update main.yml
Enngage Sep 27, 2024
8026580
Update main.yml
Enngage Sep 27, 2024
a989302
Update main.yml
Enngage Sep 27, 2024
0331987
Update main.yml
Enngage Sep 27, 2024
6c0b1d1
Update main.yml
Enngage Sep 27, 2024
9d83151
Update main.yml
Enngage Sep 27, 2024
ffc5a5a
Updates GH workflow
Enngage Sep 27, 2024
129d736
Update build.yml
Enngage Sep 27, 2024
0689fce
Removes lint from build
Enngage Sep 27, 2024
95d7fca
Converts assert -> with import of package.json
Enngage Sep 27, 2024
987ce24
Removes 'path' config from dotenv
Enngage Sep 27, 2024
1c34124
Renames tests -> samples directory for scripts, updates naming of scr…
Enngage Sep 27, 2024
fd9bc10
Removes "node" folder and moves "cli" under "lib" directly
Enngage Sep 27, 2024
c494bd4
Updates readme to use npx samples
Enngage Sep 27, 2024
1c36ae8
Update README.md
Enngage Sep 27, 2024
0a68b4c
Update README.md
Enngage Sep 27, 2024
4552fc3
Removes 'preferGlobal' from package.json
Enngage Sep 27, 2024
0175c0b
Updates toPascalCase regex
Enngage Sep 27, 2024
91bdc00
Updates the way default module resolution is resolved
Enngage Sep 30, 2024
0803a6f
renames generator.utils & creates local function to generate types
Enngage Sep 30, 2024
04f34d8
Reuses existing type instead
Enngage Sep 30, 2024
1e37d34
Refactors the way files / barrel files are created to make it more st…
Enngage Sep 30, 2024
3e93779
Simplifies regex
Enngage Sep 30, 2024
71f4aea
Refactors 'moduleResolution' option to use 'ModuleFileExtension' whic…
Enngage Sep 30, 2024
6016428
Update commands.ts
Enngage Sep 30, 2024
321f102
updates deps & moves delivery sdk from devDeps to deps
Enngage Oct 1, 2024
a7254cd
Update package.json
Enngage Oct 1, 2024
2292286
Refactors items generator to use Delivery API instead of Management A…
Enngage Oct 1, 2024
b710361
updates samples
Enngage Oct 1, 2024
fbd6f29
Uses strongly typed arg names instead of string, adds few missing opt…
Enngage Oct 1, 2024
7e9029e
Adds ability to specify what files are generated for items generator
Enngage Oct 1, 2024
cdaae5a
chore(release): 8.0.0-3
Enngage Oct 1, 2024
b105a90
Adds mjs & mts file extension options, improves parsing functions & c…
Enngage Oct 2, 2024
79f8acb
Removes tsconfig.es2022.json in favor of a single ts.config & updates…
Enngage Oct 2, 2024
cafd2a2
chore(release): 8.0.0-4
Enngage Oct 2, 2024
1afb705
Adds core type representing typed IContentItem to further improve typ…
Enngage Oct 4, 2024
3161fa6
chore(release): 8.0.0-5
Enngage Oct 4, 2024
56f72a7
Fixes incorrect option name
Enngage Oct 7, 2024
c7d2c9f
Removes unused map
Enngage Oct 7, 2024
32a04b3
udpates deps
Enngage Oct 8, 2024
0b5a646
Adds tracking headers
Enngage Oct 8, 2024
a5c527d
chore(release): 8.0.0-6
Enngage Oct 8, 2024
91dc012
Generates type representing all possible element codenames
Enngage Oct 29, 2024
80d7a55
chore(release): 8.0.0-7
Enngage Oct 29, 2024
d25edd8
Uses proper import for isNotUndefined
Enngage Oct 30, 2024
9ac7468
chore(release): 8.0.0-8
Enngage Oct 30, 2024
8bffb3d
updates deps & regenerates models
Enngage Nov 11, 2024
c601a00
Generates type guards for delivery models
Enngage Nov 11, 2024
4c58a6a
fixes command path
Enngage Nov 11, 2024
8f6d4c2
chore(release): 8.0.0-9
Enngage Nov 11, 2024
70cd7e6
Fixes & simplifies toCamelCase function
Enngage Nov 11, 2024
5bdb89c
Use codename for property name by default instead of converting to ca…
Enngage Nov 11, 2024
861713d
updates samples
Enngage Nov 11, 2024
612be48
use toSafePropertyName for role codename as it may contain dashes
Enngage Nov 11, 2024
4ea6f85
chore(release): 8.0.0-10
Enngage Nov 11, 2024
ee06e15
Adds update version scripts to release scripts
Enngage Nov 11, 2024
57b7df1
Adds undefined | null to typeguard arg
Enngage Nov 11, 2024
5c39700
updates sample
Enngage Nov 11, 2024
2a3ffbd
chore(release): 8.0.0-11
Enngage Nov 11, 2024
aa13cdc
Update metadata.ts
Enngage Nov 11, 2024
b4492ef
Adds codename of type to type guard comment
Enngage Nov 12, 2024
1a978d3
Simplifies `mapName` function
Enngage Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const deliveryConfig = {
taxonomiesFolderName: `taxonomies`,
systemTypesFolderName: 'system',
coreCodenamesFilename: 'delivery.codenames',
coreTypeFilename: 'core.type',
coreContentTypeName: 'CoreContentType',

sdkTypes: {
contentItem: 'IContentItem',
Expand Down
157 changes: 93 additions & 64 deletions lib/generators/delivery/delivery-content-type.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,11 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato
taxonomy: mapName(config.nameResolvers?.taxonomy, 'pascalCase')
};

const getSystemTypeImports = (): readonly string[] => {
const getContentTypeSystemImports = (): readonly string[] => {
return [
importer.importType({
filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${deliveryConfig.coreCodenamesFilename}.ts`,
importValue: [
sharedTypesConfig.collectionCodenames,
sharedTypesConfig.languageCodenames,
sharedTypesConfig.workflowCodenames,
sharedTypesConfig.workflowStepCodenames
]
.map((m) => m)
.join(', ')
filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${coreConfig.barrelExportFilename}`,
importValue: [deliveryConfig.coreContentTypeName].map((m) => m).join(', ')
Enngage marked this conversation as resolved.
Show resolved Hide resolved
})
];
};
Expand Down Expand Up @@ -198,7 +191,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato
return {
imports: sortAlphabetically(
[
...getSystemTypeImports(),
...getContentTypeSystemImports(),
...getReferencedTypeImports(data.contentType, data.flattenedElements),
...getReferencedTaxonomyImports(data.flattenedElements),
...getSnippetImports(snippets)
Expand Down Expand Up @@ -239,15 +232,15 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato
};
};

const getDeliverySdkImports = (
const getTypeDeliverySdkImports = (
typeOrSnippet: ContentTypeOrSnippet,
flattenedElements: readonly FlattenedElement[]
): readonly string[] => {
const mainType =
typeOrSnippet instanceof ContentTypeModels.ContentType ? deliveryConfig.sdkTypes.contentItem : deliveryConfig.sdkTypes.snippet;

return sortAlphabetically(
[mainType, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])],
[
...(typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet ? [deliveryConfig.sdkTypes.snippet] : []),
...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])
],
(importValue) => importValue
);
};
Expand All @@ -270,7 +263,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato
return `
${importer.importType({
filePathOrPackage: deliveryConfig.npmPackageName,
importValue: `${getDeliverySdkImports(snippet, flattenedElements).join(', ')}`
importValue: `${getTypeDeliverySdkImports(snippet, flattenedElements).join(', ')}`
})}
${importsResult.imports.join('\n')}

Expand Down Expand Up @@ -308,7 +301,7 @@ ${getElementsCode(flattenedElements)}>;
return `
${importer.importType({
filePathOrPackage: deliveryConfig.npmPackageName,
importValue: `${getDeliverySdkImports(contentType, flattenedElements).join(', ')}`
importValue: `${getTypeDeliverySdkImports(contentType, flattenedElements).join(', ')}`
})}
${importsResult.imports.join('\n')}

Expand All @@ -323,14 +316,9 @@ ${wrapComment(`
* Id: ${contentType.id}
* Codename: ${contentType.codename}
`)}
export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.contentItem}<
export type ${importsResult.typeName} = ${deliveryConfig.coreContentTypeName}<
${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${importsResult.contentTypeExtends}` : ''},
'${contentType.codename}',
${sharedTypesConfig.languageCodenames},
${sharedTypesConfig.collectionCodenames},
${sharedTypesConfig.workflowCodenames},
${sharedTypesConfig.workflowStepCodenames},
${nameOfTypeRepresentingAllElementCodenames}>;
'${contentType.codename}'>;
`;
};

Expand Down Expand Up @@ -391,12 +379,6 @@ ${nameOfTypeRepresentingAllElementCodenames}>;
if (flattenedElements.length === 0) {
return `export type ${typeName} = never`;
}

const el = flattenedElements.find((m) => m.codename === 'link__f25fb651_eea8_4a0a_8e39_ac5a0f97ed72');
if (el) {
console.log(el);
}

return `export type ${typeName} = ${flattenedElements.map((element) => `'${element.codename}'`).join(' | ')};`;
};

Expand All @@ -406,24 +388,27 @@ ${nameOfTypeRepresentingAllElementCodenames}>;
.with({ type: 'text' }, () => 'TextElement')
.with({ type: 'number' }, () => 'NumberElement')
.with({ type: 'modular_content' }, (linkedItemsElement) => {
if (!linkedItemsElement.allowedContentTypes?.length) {
return 'LinkedItemsElement';
}
return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`;
return `LinkedItemsElement<${
linkedItemsElement.allowedContentTypes?.length
? getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes).join(' | ')
: deliveryConfig.coreContentTypeName
}>`;
})
.with({ type: 'subpages' }, (linkedItemsElement) => {
if (!linkedItemsElement.allowedContentTypes?.length) {
return 'LinkedItemsElement';
}
return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`;
return `LinkedItemsElement<${
linkedItemsElement.allowedContentTypes?.length
? getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes).join(' | ')
: deliveryConfig.coreContentTypeName
}>`;
})
.with({ type: 'asset' }, () => 'AssetsElement')
.with({ type: 'date_time' }, () => 'DateTimeElement')
.with({ type: 'rich_text' }, (richTextElement) => {
if (!richTextElement.allowedContentTypes?.length) {
return 'RichTextElement';
}
return `RichTextElement<${getLinkedItemsAllowedTypes(richTextElement.allowedContentTypes ?? []).join(' | ')}>`;
return `RichTextElement<${
richTextElement.allowedContentTypes?.length
? getLinkedItemsAllowedTypes(richTextElement.allowedContentTypes).join(' | ')
: deliveryConfig.coreContentTypeName
}>`;
})
.with({ type: 'multiple_choice' }, (multipleChoiceElement) => {
if (!multipleChoiceElement.multipleChoiceOptions?.length) {
Expand Down Expand Up @@ -451,6 +436,70 @@ ${nameOfTypeRepresentingAllElementCodenames}>;
return types.map((type) => nameResolvers.contentType(type));
};

const getCoreContentTypeFile = (): GeneratedFile => {
const sdkImports: string[] = [deliveryConfig.sdkTypes.contentItem, deliveryConfig.sdkTypes.contentItemElements];

const codenameImports: string[] = [
sharedTypesConfig.contentTypeCodenames,
sharedTypesConfig.collectionCodenames,
sharedTypesConfig.languageCodenames,
sharedTypesConfig.workflowCodenames,
sharedTypesConfig.workflowStepCodenames
];

const contentTypeGenericArgName: string = 'TContentTypeCodename';
const elementsGenericArgName: string = 'TElements';

return {
filename: `${deliveryConfig.coreTypeFilename}.ts`,
text: `
${importer.importType({
filePathOrPackage: deliveryConfig.npmPackageName,
importValue: `${sdkImports.join(', ')}`
})}
${importer.importType({
filePathOrPackage: `./${deliveryConfig.coreCodenamesFilename}.ts`,
importValue: `${codenameImports.join(', ')}`
})}

${wrapComment(`\n * Core content type used in favor of generic '${deliveryConfig.sdkTypes.contentItem}'\n`)}
export type ${deliveryConfig.coreContentTypeName}<
${elementsGenericArgName} extends ${deliveryConfig.sdkTypes.contentItemElements} = ${deliveryConfig.sdkTypes.contentItemElements},
${contentTypeGenericArgName} extends ${sharedTypesConfig.contentTypeCodenames} = ${sharedTypesConfig.contentTypeCodenames}
> = ${deliveryConfig.sdkTypes.contentItem}<
${elementsGenericArgName},
${contentTypeGenericArgName},
${sharedTypesConfig.languageCodenames},
${sharedTypesConfig.collectionCodenames},
${sharedTypesConfig.workflowCodenames},
${sharedTypesConfig.workflowStepCodenames}
>;
`
};
};

const getCodenamesFile = (): GeneratedFile => {
return {
filename: `${deliveryConfig.coreCodenamesFilename}.ts`,
text: `
${wrapComment(`\n * Type representing all languages\n`)}
${getLanguageCodenamesType(config.environmentData.languages)}

${wrapComment(`\n * Type representing all content types\n`)}
${getContentTypeCodenamesType(config.environmentData.types)}

${wrapComment(`\n * Type representing all collections\n`)}
${getCollectionCodenamesType(config.environmentData.collections)}

${wrapComment(`\n * Type representing all workflows\n`)}
${getWorkflowCodenamesType(config.environmentData.workflows)}

${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)}
${getWorkflowStepCodenamesType(config.environmentData.workflows)}
`
};
};

return {
generateModels: (): {
contentTypeFiles: GeneratedSet;
Expand All @@ -470,27 +519,7 @@ ${nameOfTypeRepresentingAllElementCodenames}>;
getSystemFiles(): GeneratedSet {
return {
folderName: deliveryConfig.systemTypesFolderName,
files: [
{
filename: `${deliveryConfig.coreCodenamesFilename}.ts`,
text: `
${wrapComment(`\n * Type representing all languages\n`)}
${getLanguageCodenamesType(config.environmentData.languages)}

${wrapComment(`\n * Type representing all content types\n`)}
${getContentTypeCodenamesType(config.environmentData.types)}

${wrapComment(`\n * Type representing all collections\n`)}
${getCollectionCodenamesType(config.environmentData.collections)}

${wrapComment(`\n * Type representing all workflows\n`)}
${getWorkflowCodenamesType(config.environmentData.workflows)}

${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)}
${getWorkflowStepCodenamesType(config.environmentData.workflows)}
`
}
]
files: [getCoreContentTypeFile(), getCodenamesFile()]
};
}
};
Expand Down
13 changes: 4 additions & 9 deletions sample/delivery/content-types/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* -------------------------------------------------------------------------------
**/

import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk';
import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js';
import type { Elements } from '@kontent-ai/delivery-sdk';
import type { CoreContentType } from '../system/index.js';

/**
* Type representing all available element codenames for Actor
Expand All @@ -27,7 +27,7 @@ export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo'
* Id: 58099989-319f-495f-aa36-cb3710854e36
Enngage marked this conversation as resolved.
Show resolved Hide resolved
* Codename: actor
*/
export type Actor = IContentItem<
export type Actor = CoreContentType<
{
/**
* Url
Expand Down Expand Up @@ -67,10 +67,5 @@ export type Actor = IContentItem<
*/
readonly photo: Elements.AssetsElement;
},
'actor',
LanguageCodenames,
CollectionCodenames,
WorkflowCodenames,
WorkflowStepCodenames,
ActorElementCodenames
'actor'
>;
44 changes: 19 additions & 25 deletions sample/delivery/content-types/movie.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
/**
* This file has been auto-generated by '@kontent-ai/[email protected]'.
*
* (c) Kontent.ai
*
* -------------------------------------------------------------------------------
*
* Project: Movie Database
* Environment: Production
* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9
*
* -------------------------------------------------------------------------------
**/

/**
* This file has been auto-generated by '@kontent-ai/[email protected]'.
*
* (c) Kontent.ai
*
* -------------------------------------------------------------------------------
*
* Project: Movie Database
* Environment: Production
* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9
*
* -------------------------------------------------------------------------------
**/

import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk';
import type { Actor } from './index.js';
import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js';
import type { Elements } from '@kontent-ai/delivery-sdk';
import type { CoreContentType } from '../system/index.js';
import type { Releasecategory } from '../taxonomies/index.js';
import type { Actor } from './index.js';

/**
* Type representing all available element codenames for Movie
Expand All @@ -38,7 +37,7 @@ export type MovieElementCodenames =
* Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c
* Codename: movie
*/
export type Movie = IContentItem<
export type Movie = CoreContentType<
{
/**
* Title
Expand All @@ -57,7 +56,7 @@ export type Movie = IContentItem<
* Codename: plot
* Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce
*/
readonly plot: Elements.RichTextElement;
readonly plot: Elements.RichTextElement<CoreContentType>;
/**
* Released
*
Expand Down Expand Up @@ -124,10 +123,5 @@ export type Movie = IContentItem<
*/
readonly releasecategory: Elements.TaxonomyElement<Releasecategory, 'releasecategory'>;
},
'movie',
LanguageCodenames,
CollectionCodenames,
WorkflowCodenames,
WorkflowStepCodenames,
MovieElementCodenames
'movie'
>;
31 changes: 31 additions & 0 deletions sample/delivery/system/core.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/**
* This file has been auto-generated by '@kontent-ai/[email protected]'.
*
* (c) Kontent.ai
*
* -------------------------------------------------------------------------------
*
* Project: Movie Database
* Environment: Production
* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9
*
* -------------------------------------------------------------------------------
**/

import type { IContentItem, IContentItemElements } from '@kontent-ai/delivery-sdk';
import type {
ContentTypeCodenames,
CollectionCodenames,
LanguageCodenames,
WorkflowCodenames,
WorkflowStepCodenames
} from './delivery.codenames.js';

/**
* Core content type used in favor of generic 'IContentItem'
*/
export type CoreContentType<
TElements extends IContentItemElements = IContentItemElements,
TContentTypeCodename extends ContentTypeCodenames = ContentTypeCodenames
> = IContentItem<TElements, TContentTypeCodename, LanguageCodenames, CollectionCodenames, WorkflowCodenames, WorkflowStepCodenames>;
1 change: 1 addition & 0 deletions sample/delivery/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
* -------------------------------------------------------------------------------
**/

export * from './core.type.js';
export * from './delivery.codenames.js';