Skip to content

Commit ccf561d

Browse files
committed
Merge branch 'master' into language-typeguards
2 parents 763ed2f + cb4ced2 commit ccf561d

File tree

21 files changed

+199
-18
lines changed

21 files changed

+199
-18
lines changed

CHANGELOG.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
# Changelog
22

3-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
3+
All notable changes to this project will be documented in this file. See
4+
[standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
45

56
## [9.0.0-0](https://github.com/kontent-ai/model-generator-js/compare/v8.1.0...v9.0.0-0) (2025-04-15)
67

7-
88
### Features
99

10-
* Extends support for types / type guards for Delivery for more entity types (i.e. collections. languages, workflows...) ([613648e](https://github.com/kontent-ai/model-generator-js/commit/613648ed4cdbcf2cd5462282275ad51007386622))
11-
* updates deps ([6d87a64](https://github.com/kontent-ai/model-generator-js/commit/6d87a64aeba93f59627e11f54e1956e3b6208eb9))
10+
- Extends support for types / type guards for Delivery for more entity types (i.e. collections. languages, workflows...)
11+
([613648e](https://github.com/kontent-ai/model-generator-js/commit/613648ed4cdbcf2cd5462282275ad51007386622))
12+
- updates deps ([6d87a64](https://github.com/kontent-ai/model-generator-js/commit/6d87a64aeba93f59627e11f54e1956e3b6208eb9))
1213

13-
## [8.1.0](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0...v8.1.0) (2025-04-08)
14+
### [8.1.1](https://github.com/kontent-ai/model-generator-js/compare/v8.1.0...v8.1.1) (2025-04-22)
1415

16+
### Bug Fixes
1517

16-
### Features
18+
- Correctly imports CoreContentType in snippet when all types are allowed in RTE, linkes items or subpages element
19+
([96f33c7](https://github.com/kontent-ai/model-generator-js/commit/96f33c7ac84c09edd7ff2983aa35b9227f881c2e))
1720

18-
* updates deps ([1fef000](https://github.com/kontent-ai/model-generator-js/commit/1fef0002792c59be1e9163bf0fd1aaf4e6b13d53))
21+
## [8.1.0](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0...v8.1.0) (2025-04-08)
22+
23+
### Features
1924

25+
- updates deps ([1fef000](https://github.com/kontent-ai/model-generator-js/commit/1fef0002792c59be1e9163bf0fd1aaf4e6b13d53))
2026

2127
### Bug Fixes
2228

23-
* Skips invalid reference to taxonomies. Usually caused by deleting a taxonomy and not updating it's references in content types / snippets ([598bad3](https://github.com/kontent-ai/model-generator-js/commit/598bad338139f3d87750ab7bcb903e5d00cb15da))
29+
- Skips invalid reference to taxonomies. Usually caused by deleting a taxonomy and not updating it's references in content types / snippets
30+
([598bad3](https://github.com/kontent-ai/model-generator-js/commit/598bad338139f3d87750ab7bcb903e5d00cb15da))
2431

2532
## [8.0.0-0](https://github.com/kontent-ai/model-generator-js/compare/v7.4.0...v8.0.0-0) (2024-09-16)
2633

lib/generators/delivery/delivery-type.generator.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export function deliveryTypeGenerator(config: DeliveryTypeGeneratorConfig) {
150150
})
151151
};
152152

153-
const getContentTypeSystemImports = (): readonly string[] => {
153+
const getCoreTypeImports = (): readonly string[] => {
154154
return [
155155
importer.importType({
156156
filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${coreConfig.barrelExportFilename}`,
@@ -159,6 +159,21 @@ export function deliveryTypeGenerator(config: DeliveryTypeGeneratorConfig) {
159159
];
160160
};
161161

162+
const shouldImportCoreTypeInSnippet = (snippet: Readonly<ContentTypeSnippetModels.ContentTypeSnippet>): boolean => {
163+
return snippet.elements
164+
.map<boolean>((m) =>
165+
match(m)
166+
.returnType<boolean>()
167+
.with(
168+
P.union({ type: 'modular_content' }, { type: 'subpages' }, { type: 'rich_text' }),
169+
(elementWithAllowedContentTypes) =>
170+
(elementWithAllowedContentTypes.allowed_content_types?.length ?? 0) > 0 ? false : true
171+
)
172+
.otherwise(() => false)
173+
)
174+
.some((m) => m === true);
175+
};
176+
162177
const getSnippetImports = (snippets: readonly Readonly<ContentTypeSnippetModels.ContentTypeSnippet>[]): readonly string[] => {
163178
if (snippets.length === 0) {
164179
return [];
@@ -169,7 +184,6 @@ export function deliveryTypeGenerator(config: DeliveryTypeGeneratorConfig) {
169184
filePathOrPackage: `../${deliveryConfig.itemSnippetsFolderName}/${coreConfig.barrelExportFilename}`,
170185
importValue: snippets
171186
.map((snippet) => nameResolvers.snippet(snippet))
172-
.map((m) => m)
173187
.filter(uniqueFilter)
174188
.join(', ')
175189
})
@@ -272,7 +286,7 @@ export function deliveryTypeGenerator(config: DeliveryTypeGeneratorConfig) {
272286
return {
273287
imports: sortAlphabetically(
274288
[
275-
...getContentTypeSystemImports(),
289+
...getCoreTypeImports(),
276290
...getReferencedTypeImports(data.contentType, data.flattenedElements),
277291
...getReferencedTaxonomyImports(data.contentType, data.flattenedElements),
278292
...getSnippetImports(snippets)
@@ -300,6 +314,7 @@ export function deliveryTypeGenerator(config: DeliveryTypeGeneratorConfig) {
300314
return {
301315
imports: sortAlphabetically(
302316
[
317+
...(shouldImportCoreTypeInSnippet(data.snippet) ? getCoreTypeImports() : []),
303318
...getReferencedTypeImports(data.snippet, data.flattenedElements),
304319
...getReferencedTaxonomyImports(data.snippet, data.flattenedElements),
305320
...getSnippetImports(snippets)

lib/meta/metadata.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
export const libMetadata = {
32
host: 'npmjs.com',
4-
name: '@kontent-ai/model-generator',
3+
name: '@kontent-ai/model-generator',
54
timestamp: 'Tue, 15 Apr 2025 15:25:59 GMT',
65
version: '9.0.0-0'
76
};

tests/integration/snapshots/delivery-sdk/basic-js/itemTypes/contentTypeWithAllElements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export type ContentTypeWithAllElementsElementCodenames =
120120
| 'asset_element'
121121
| 'multiple_choice_element'
122122
| 'number_element'
123+
| 'snippet_a__rich_text_with_all_allowed_item_types'
123124
| 'snippet_a__linked_items_with_specific_types'
124125
| 'snippet_a__text'
125126
| 'taxonomy_element';

tests/integration/snapshots/delivery-sdk/basic-js/itemTypes/contentTypeWithSnippetOnly.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export type ContentTypeWithSnippetOnly = CoreItem<
1616
/**
1717
* Type representing all available element codenames for Content type with snippet only
1818
*/
19-
export type ContentTypeWithSnippetOnlyElementCodenames = 'snippet_a__linked_items_with_specific_types' | 'snippet_a__text';
19+
export type ContentTypeWithSnippetOnlyElementCodenames =
20+
| 'snippet_a__rich_text_with_all_allowed_item_types'
21+
| 'snippet_a__linked_items_with_specific_types'
22+
| 'snippet_a__text';
2023

2124
/**
2225
* Type guard for Content type with snippet only

tests/integration/snapshots/delivery-sdk/basic-ts/itemTypes/contentTypeWithAllElements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export type ContentTypeWithAllElementsElementCodenames =
120120
| 'asset_element'
121121
| 'multiple_choice_element'
122122
| 'number_element'
123+
| 'snippet_a__rich_text_with_all_allowed_item_types'
123124
| 'snippet_a__linked_items_with_specific_types'
124125
| 'snippet_a__text'
125126
| 'taxonomy_element';

tests/integration/snapshots/delivery-sdk/basic-ts/itemTypes/contentTypeWithSnippetOnly.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export type ContentTypeWithSnippetOnly = CoreItem<
1616
/**
1717
* Type representing all available element codenames for Content type with snippet only
1818
*/
19-
export type ContentTypeWithSnippetOnlyElementCodenames = 'snippet_a__linked_items_with_specific_types' | 'snippet_a__text';
19+
export type ContentTypeWithSnippetOnlyElementCodenames =
20+
| 'snippet_a__rich_text_with_all_allowed_item_types'
21+
| 'snippet_a__linked_items_with_specific_types'
22+
| 'snippet_a__text';
2023

2124
/**
2225
* Type guard for Content type with snippet only

tests/integration/snapshots/delivery-sdk/custom-format-options/itemTypes/contentTypeWithAllElements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ContentTypeWithAllElementsElementCodenames,
109109
/**
110110
* Type representing all available element codenames for Content type with all elements
111111
*/
112-
export type ContentTypeWithAllElementsElementCodenames = 'text_element' | 'url_slug_element' | 'rich_text_element' | 'date___time_element' | 'custom_element' | 'linked_items_element' | 'asset_element' | 'multiple_choice_element' | 'number_element' | 'snippet_a__linked_items_with_specific_types' | 'snippet_a__text' | 'taxonomy_element';;
112+
export type ContentTypeWithAllElementsElementCodenames = 'text_element' | 'url_slug_element' | 'rich_text_element' | 'date___time_element' | 'custom_element' | 'linked_items_element' | 'asset_element' | 'multiple_choice_element' | 'number_element' | 'snippet_a__rich_text_with_all_allowed_item_types' | 'snippet_a__linked_items_with_specific_types' | 'snippet_a__text' | 'taxonomy_element';;
113113

114114
/**
115115
* Type guard for Content type with all elements

tests/integration/snapshots/delivery-sdk/custom-format-options/itemTypes/contentTypeWithSnippetOnly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Record<string, never> & SnippetA,
1717
/**
1818
* Type representing all available element codenames for Content type with snippet only
1919
*/
20-
export type ContentTypeWithSnippetOnlyElementCodenames = 'snippet_a__linked_items_with_specific_types' | 'snippet_a__text';;
20+
export type ContentTypeWithSnippetOnlyElementCodenames = 'snippet_a__rich_text_with_all_allowed_item_types' | 'snippet_a__linked_items_with_specific_types' | 'snippet_a__text';;
2121

2222
/**
2323
* Type guard for Content type with snippet only

tests/integration/snapshots/delivery-sdk/name-and-file-resolvers/itemTypes/content_type_content_type_with_all_elements.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export type ContentType_content_type_with_all_elementsElementCodenames =
120120
| 'asset_element'
121121
| 'multiple_choice_element'
122122
| 'number_element'
123+
| 'snippet_a__rich_text_with_all_allowed_item_types'
123124
| 'snippet_a__linked_items_with_specific_types'
124125
| 'snippet_a__text'
125126
| 'taxonomy_element';

0 commit comments

Comments
 (0)