From 920e22a6909dee63d7f37b4490688401cd98bc9b Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Tue, 20 Aug 2024 10:33:58 +0200 Subject: [PATCH 1/3] Fixed LinkedDefinitions in @sap/cds --- apis/internal/util.d.ts | 17 +---------------- test/typescript/apis/project/cds-linked.ts | 11 ----------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/apis/internal/util.d.ts b/apis/internal/util.d.ts index 185c3d9a..0e6d07b6 100644 --- a/apis/internal/util.d.ts +++ b/apis/internal/util.d.ts @@ -10,23 +10,8 @@ type Without = { [P in Exclude]?: never } /** @internal */ export type XOR = (T | U) extends object ? (Without & U) | (Without & T) : T | U -// "ArrayLike" is taken since es5, so the underscore is both for @internal and to avoid clashes -/** - * A subset of array-like methods, but not `ArrayLike`, as it does not expose `.length`. - * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#iterable) - * @internal - * @since cds 7.9 - */ -export type _ArrayLike = Iterable & { - forEach: (handler: (element: T) => any) => void, - filter: (predicate: (element: T) => boolean) => Array, - map: (converter: (element: T) => R) => Array, - some: (predicate: (element: T) => boolean) => boolean, - find: (predicate: (element: T) => boolean) => T | undefined, -} - /** * Object structure that exposes both array-like and object-like behaviour. * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#iterable) */ -export type IterableMap = { [name: string]: T } & _ArrayLike +export type IterableMap = { [name: string]: T } & Iterable diff --git a/test/typescript/apis/project/cds-linked.ts b/test/typescript/apis/project/cds-linked.ts index 7b7c87fc..3a42d4b8 100644 --- a/test/typescript/apis/project/cds-linked.ts +++ b/test/typescript/apis/project/cds-linked.ts @@ -1,5 +1,4 @@ import { LinkedCSN } from '../../../../apis/linked'; -import { _ArrayLike } from '../../../../apis/internal/util'; import cds from '@sap/cds'; import { csn } from '../../../..'; import { as } from './dummy'; @@ -88,16 +87,6 @@ mixin(class {}, class {}) // @ts-expect-error mixin(42) -const arr: _ArrayLike = as<_ArrayLike>() -// @ts-expect-error -arr.length -const v: void = arr.forEach(x => x + 1) -const s: string[] = arr.map(x => ''+x) -const xs: number[] = arr.filter(x => x > 0) -const x: number | undefined = arr.find(x => x > 0) -const b: boolean = arr.some(x => x > 0) -for (const n of arr) n + 1 - // spot check to make sure linked classes are properly exposed cds.linked.classes... cds.linked.classes.entity === entity // @ts-expect-error From 12004236d16832becc47ea555d8068f0346b6c2d Mon Sep 17 00:00:00 2001 From: Daniel O'Grady Date: Mon, 2 Sep 2024 13:45:21 +0200 Subject: [PATCH 2/3] Fix tests --- test/typescript/apis/project/cds-linked.ts | 16 ++++++++-------- test/typescript/apis/project/cds-services.ts | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/typescript/apis/project/cds-linked.ts b/test/typescript/apis/project/cds-linked.ts index 3a42d4b8..8b8afe23 100644 --- a/test/typescript/apis/project/cds-linked.ts +++ b/test/typescript/apis/project/cds-linked.ts @@ -29,8 +29,8 @@ csnStruct.is_struct linkedCsn.exports[0].name linkedCsn.exports['foo'].name // @ts-expect-error only for entities and services -linkedCsn.exports('foo').bar -linkedCsn.exports.map(e => e.kind) +linkedCsn.exports('foo').bar; +[...linkedCsn.exports].map(e => e.kind) linkedCsn.entities('foo') const es: cds.linked.classes.entity[] = linkedCsn.all(x => Boolean(x.name), linkedCsn.entities) // @ts-expect-error @@ -39,15 +39,15 @@ const one: cds.linked.classes.entity | undefined = linkedCsn.find(x => Boolean(x for (const each of linkedCsn.each(e => true, linkedCsn.entities)) each.keys new entity().kind === 'entity' -new entity().keys.find -new entity().associations.find(Boolean) -new entity().compositions.find(Boolean) -new entity().actions.find(Boolean) +new entity().keys.find; +[...new entity().associations].find(Boolean); +[...new entity().compositions].find(Boolean); +[...new entity().actions].find(Boolean) new entity().texts?.kind === 'entity' new entity().drafts?.kind === 'entity' new entity().is_entity === true -new entity().is_struct === true -new entity().elements.find(x => x.items.kind === 'type') +new entity().is_struct === true; +[...new entity().elements].find(x => x.items.kind === 'type') new entity().items?.kind new entity().name // @ts-expect-error diff --git a/test/typescript/apis/project/cds-services.ts b/test/typescript/apis/project/cds-services.ts index 8d62f8a8..2379d2b9 100644 --- a/test/typescript/apis/project/cds-services.ts +++ b/test/typescript/apis/project/cds-services.ts @@ -344,11 +344,11 @@ const outboxedService = cds.outboxed(srv) await outboxedService.send({ event: 'feeEstimation', entity: networkGroups, data: {name:'Volta'}}) await cds.unboxed(outboxedService).send({ event: 'feeEstimation', entity: networkGroups, data: {name:'Volta'}}) -srv.entities('namespace') -srv.entities('namespace').map(e => e.keys) // .keys only available on entities +srv.entities('namespace'); +[...srv.entities('namespace')].map(e => e.keys); // .keys only available on entities // @ts-expect-error -srv.events('namespace').map(e => e.keys) -srv.events('namespace').map(e => e.elements) +[...srv.events('namespace')].map(e => e.keys); +[...srv.events('namespace')].map(e => e.elements) // @ts-expect-error srv.entities('namespace')('and again') From 04a03384553d87cf4596e1de009b48002ead224c Mon Sep 17 00:00:00 2001 From: Daniel O'Grady Date: Mon, 2 Sep 2024 13:51:13 +0200 Subject: [PATCH 3/3] Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36513172..de52f4a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ### Fixed - The `@types/sap__cds` link created by the `postinstall` script now also works in monorepo setups where the target `@cap-js/cds-types` might already be preinstalled (often hoisted some levels up). +### Removed +- Removed array-like methods from model parts (`.map`, `.find`, etc.). To still use them, apply spreading to object in question first. + ## Version 0.6.4 - 2024-08-05 ### Added - `Service.emit(...)` can now also be called with custom events