Skip to content

Commit

Permalink
fix: type mismatch (#900)
Browse files Browse the repository at this point in the history
* fix: type mismatch

* chore: fix lint error

* chore: fix lint error

* chore: remove autogenerated comments

* chore: add changesets
  • Loading branch information
voicis authored Dec 5, 2024
1 parent c499009 commit d581d62
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-berries-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/vocabularies-types': patch
---

Export `ArrayWithType` type definition.
6 changes: 6 additions & 0 deletions .changeset/many-lemons-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sap-ux/annotation-converter': minor
'@sap-ux/edmx-parser': minor
---

**BREAKING CHANGE**: parser and writeback no longer incorrectly convert string Collections entries as `string`. Now returned values correctly match the `StringExpression` type and function signatures.
10 changes: 7 additions & 3 deletions packages/annotation-converter/src/writeback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type {
PathExpression,
PropertyPathExpression,
RawAnnotation,
Reference
Reference,
StringExpression
} from '@sap-ux/vocabularies-types';
import { unalias } from './utils';

Expand Down Expand Up @@ -213,14 +214,17 @@ function revertCollectionItemToRawType(
collectionItem: any
):
| AnnotationRecord
| string
| StringExpression
| PropertyPathExpression
| PathExpression
| NavigationPropertyPathExpression
| AnnotationPathExpression
| undefined {
if (typeof collectionItem === 'string') {
return collectionItem;
return {
type: 'String',
String: collectionItem
};
} else if (typeof collectionItem === 'object') {
if (collectionItem.hasOwnProperty('$Type')) {
// Annotation Record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,10 @@ exports[`Writeback capabilities can revert further SideEffects definition 1`] =
"name": "TargetProperties",
"value": {
"Collection": [
"WarrantyYear",
{
"String": "WarrantyYear",
"type": "String",
},
],
"type": "Collection",
},
Expand Down
12 changes: 9 additions & 3 deletions packages/edmx-parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
AnnotationList,
AnnotationPathExpression,
AnnotationRecord,
ArrayWithType,
Expression,
FullyQualifiedName,
NavigationPropertyPathExpression,
Expand Down Expand Up @@ -705,9 +706,14 @@ function parseCollection(
(navPropertyPathArray as any).type = 'NavigationPropertyPath';
return navPropertyPathArray;
} else if (isExpressionOfType<EDMX.StringCollectionWrapper>(collection, 'String')) {
const stringArray = ensureArray(collection.String).map((stringValue) => stringValue._text);
(stringArray as any).type = 'String';
return stringArray as unknown as StringExpression[];
const stringArray: ArrayWithType<StringExpression, 'String'> = ensureArray(collection.String).map(
(stringValue): StringExpression => ({
type: 'String',
String: stringValue._text
})
);
stringArray.type = 'String';
return stringArray;
} else if (isExpressionOfType<EDMX.AnnotationPathCollectionWrapper>(collection, 'AnnotationPath')) {
const annotationPathArray = ensureArray(collection.AnnotationPath).map(
(annotationPath) => parseModelPath(annotationPath, 'AnnotationPath') as AnnotationPathExpression
Expand Down
40 changes: 32 additions & 8 deletions packages/edmx-parser/test/__snapshots__/parser.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13425,7 +13425,10 @@ RawMetadataInstance {
},
{
"collection": [
"SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
{
"String": "SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
"type": "String",
},
],
"qualifier": undefined,
"term": "com.sap.vocabularies.Common.v1.DraftActivationVia",
Expand Down Expand Up @@ -13566,7 +13569,10 @@ RawMetadataInstance {
},
{
"collection": [
"SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
{
"String": "SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
"type": "String",
},
],
"qualifier": undefined,
"term": "com.sap.vocabularies.Common.v1.DraftActivationVia",
Expand Down Expand Up @@ -28808,7 +28814,10 @@ RawMetadataInstance {
},
{
"collection": [
"SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
{
"String": "SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
"type": "String",
},
],
"qualifier": undefined,
"term": "com.sap.vocabularies.Common.v1.DraftActivationVia",
Expand Down Expand Up @@ -28843,7 +28852,10 @@ RawMetadataInstance {
},
{
"collection": [
"SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
{
"String": "SEPMRA_PROD_MAN.SEPMRA_PROD_MAN_Entities/SEPMRA_C_PD_Product",
"type": "String",
},
],
"qualifier": undefined,
"term": "com.sap.vocabularies.Common.v1.DraftActivationVia",
Expand Down Expand Up @@ -35603,7 +35615,10 @@ RawMetadataInstance {
"annotations": [
{
"collection": [
undefined,
{
"String": undefined,
"type": "String",
},
],
"qualifier": undefined,
"term": "com.sap.vocabularies.Common.v1.ValueListRelevantQualifiers",
Expand Down Expand Up @@ -111901,9 +111916,18 @@ RawMetadataInstance {
"name": "Transformations",
"value": {
"Collection": [
"aggregate",
"groupby",
"filter",
{
"String": "aggregate",
"type": "String",
},
{
"String": "groupby",
"type": "String",
},
{
"String": "filter",
"type": "String",
},
],
"type": "Collection",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/vocabularies-types/src/BaseEdm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type GenericExpression<K extends keyof any, T> = {
} & {
type: K;
};
type ArrayWithType<T, K> = T[] & { type?: K };
export type ArrayWithType<T, K> = T[] & { type?: K };

export type Apply = any;
export type If = any;
Expand Down

0 comments on commit d581d62

Please sign in to comment.