From 51c6f249318b3a28c24c6107f6daf461c1852672 Mon Sep 17 00:00:00 2001 From: Daniel O'Grady <103028279+daogrady@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:27:00 +0200 Subject: [PATCH] Move minify to compile.ts (#295) --- apis/compile.d.ts | 7 +++++++ apis/facade.d.ts | 1 + apis/models.d.ts | 8 +------- apis/server.d.ts | 1 + test/typescript/apis/project/cds-compile.ts | 3 +++ test/typescript/apis/project/cds-linked.ts | 4 +++- 6 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 apis/compile.d.ts create mode 100644 test/typescript/apis/project/cds-compile.ts diff --git a/apis/compile.d.ts b/apis/compile.d.ts new file mode 100644 index 00000000..1cf008f0 --- /dev/null +++ b/apis/compile.d.ts @@ -0,0 +1,7 @@ +import { CSN } from './csn' + +/** + * Minifies a given CSN model by removing all unused1 types and aspects, as well all entities tagged with `@cds.persistence.skip:'if-unused'` + * @see [capire](https://cap.cloud.sap/docs/node.js/cds-compile#cds-minify) + */ +export function minify (model: CSN): CSN \ No newline at end of file diff --git a/apis/facade.d.ts b/apis/facade.d.ts index 366cebd5..3556c3f1 100644 --- a/apis/facade.d.ts +++ b/apis/facade.d.ts @@ -7,6 +7,7 @@ export * from './events' export * from './utils' export * from './cqn' export * from './global' +export * from './compile' export { log, debug } from './log' export { test } from './test' diff --git a/apis/models.d.ts b/apis/models.d.ts index 48504fb1..c28ce170 100644 --- a/apis/models.d.ts +++ b/apis/models.d.ts @@ -201,12 +201,6 @@ export namespace linked { */ export function reflect (model: csn.CSN): ln.LinkedCSN -/** - * Minifies a given CSN model by removing all unused1 types and aspects, as well all entities tagged with `@cds.persistence.skip:'if-unused'` - * @see [capire](https://cap.cloud.sap/docs/node.js/cds-compile#cds-minify) - */ -export function minify (model: csn.CSN): csn.CSN - /** * Provides a set of methods to parse a given model, query or expression. * You can also use `cds.compile(csn).to('')` as a fluent variant. @@ -219,7 +213,7 @@ export const compile: { for: { odata (model: csn.CSN, o?: _options): csn.CSN, sql (model: csn.CSN, o?: _options): csn.CSN, - nodejs (mode: csn.CSN, o?: _options): csn.CSN, + nodejs (model: csn.CSN, o?: _options): linked.LinkedCSN, }, to: { parsed: { diff --git a/apis/server.d.ts b/apis/server.d.ts index 67284ee2..b162d47e 100644 --- a/apis/server.d.ts +++ b/apis/server.d.ts @@ -61,6 +61,7 @@ export const serve: (service: string, options?: { [key: string]: any, }) => Promise & cds_serve_fluent + /** * Emitted whenever a model is loaded using cds.load(). */ diff --git a/test/typescript/apis/project/cds-compile.ts b/test/typescript/apis/project/cds-compile.ts new file mode 100644 index 00000000..0efb85ff --- /dev/null +++ b/test/typescript/apis/project/cds-compile.ts @@ -0,0 +1,3 @@ +import cds from '@sap/cds' + +cds.minify({}) \ No newline at end of file diff --git a/test/typescript/apis/project/cds-linked.ts b/test/typescript/apis/project/cds-linked.ts index 879a1fbf..e3a6949b 100644 --- a/test/typescript/apis/project/cds-linked.ts +++ b/test/typescript/apis/project/cds-linked.ts @@ -113,4 +113,6 @@ cds.linked.classes.Association === cds.linked.classes.event // but make sure we can still call .linked(CSN) const ln: LinkedCSN = cds.linked({}) -const ln2: LinkedCSN | undefined = cds.context?.model \ No newline at end of file +const ln2: LinkedCSN | undefined = cds.context?.model + +cds.minify({}) \ No newline at end of file