From b71ff39d3187d86d2f01258453dbcde9531cb86c Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:11:00 +0200 Subject: [PATCH 01/10] Improve description of srv.send --- node.js/core-services.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/node.js/core-services.md b/node.js/core-services.md index fb2a45e8e..3ee8cea5b 100644 --- a/node.js/core-services.md +++ b/node.js/core-services.md @@ -796,16 +796,20 @@ return : result of this.dispatch(req) Use this method to send synchronous requests to a service for execution. -- `method` can be an HTTP method, or a name of a custom action or function +- `method` is an HTTP method - `path` can be an arbitrary URL, starting with a leading `'/'`, it is passed to a service without any modification as a string +For calling bound / unbound actions and functions from the service more variants of `srv.send` are additionally provided, +as described in the Section [Calling Actions / Functions](../guides/providing-services#calling-actions-functions). +Basically the action or function name to be used instead of the HTTP method. + Examples: ```js await srv.send('POST','/Books', { title: 'Catweazle' }) await srv.send('GET','/Books') await srv.send('GET','/Books/201') -await srv.send('submitOrder',{...}) +await srv.send('submitOrder', ...) ``` These requests would be processed by respective [event handlers](#srv-on-before-after) registered like that: From b5f4f1bf3d42f61b4e2fc33c63bb69ad62d911c0 Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:34:17 +0200 Subject: [PATCH 02/10] Update providing-services.md --- guides/providing-services.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/guides/providing-services.md b/guides/providing-services.md index c0d7f8e3d..7021ce493 100644 --- a/guides/providing-services.md +++ b/guides/providing-services.md @@ -1123,7 +1123,35 @@ POST .../sue/Foo(2)/Sue.order {"x":1} // bound action
-**Programmatic** usage via **generic APIs** would look like this for Node.js: +**Programmatic** usage via **generic APIs** for Node.js: + +For unbound actions and functions: + +```ts +async function srv.send ( + event : string | { event, data?, headers? }, + data? : object | any +) +return : result of this.dispatch(req) +``` + +For bound actions and functions: + +```ts +async function srv.send ( + event : string | { event, entity, data?, params, headers? }, + entity : string, + data? : object | any, + params : array of any, +) +return : result of this.dispatch(req) +``` + +- `event` is a name of a custom action or function +- `entity` is a name of an entity +- `params` are keys of the entity instance + +Programmatic usage would look like this for Node.js: ```js const srv = await cds.connect.to('Sue') From 7d06fbc2002124f00141be3060a57eaa6f4de5f4 Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:37:50 +0200 Subject: [PATCH 03/10] Update core-services.md --- node.js/core-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.js/core-services.md b/node.js/core-services.md index 3ee8cea5b..258e89f55 100644 --- a/node.js/core-services.md +++ b/node.js/core-services.md @@ -809,7 +809,7 @@ Examples: await srv.send('POST','/Books', { title: 'Catweazle' }) await srv.send('GET','/Books') await srv.send('GET','/Books/201') -await srv.send('submitOrder', ...) +await srv.send('submitOrder', {...}) ``` These requests would be processed by respective [event handlers](#srv-on-before-after) registered like that: From 7a05eb92284dce595293941b46c9dffca41033b2 Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:38:17 +0200 Subject: [PATCH 04/10] Update core-services.md --- node.js/core-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.js/core-services.md b/node.js/core-services.md index 258e89f55..4c45168e6 100644 --- a/node.js/core-services.md +++ b/node.js/core-services.md @@ -809,7 +809,7 @@ Examples: await srv.send('POST','/Books', { title: 'Catweazle' }) await srv.send('GET','/Books') await srv.send('GET','/Books/201') -await srv.send('submitOrder', {...}) +await srv.send('submitOrder',{...}) ``` These requests would be processed by respective [event handlers](#srv-on-before-after) registered like that: From b8df7757fb489a1372e431a58e78a33f1c5a4475 Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Mon, 23 Jun 2025 16:40:02 +0200 Subject: [PATCH 05/10] Update core-services.md --- node.js/core-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.js/core-services.md b/node.js/core-services.md index 4c45168e6..a0f4aaded 100644 --- a/node.js/core-services.md +++ b/node.js/core-services.md @@ -799,7 +799,7 @@ Use this method to send synchronous requests to a service for execution. - `method` is an HTTP method - `path` can be an arbitrary URL, starting with a leading `'/'`, it is passed to a service without any modification as a string -For calling bound / unbound actions and functions from the service more variants of `srv.send` are additionally provided, +For calling bound / unbound actions and functions from the service further variants of `srv.send` are additionally supported, as described in the Section [Calling Actions / Functions](../guides/providing-services#calling-actions-functions). Basically the action or function name to be used instead of the HTTP method. From 9922c99fb85b4da1190ab92c520bdece1ba35ada Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Mon, 23 Jun 2025 17:19:15 +0200 Subject: [PATCH 06/10] Update providing-services.md --- guides/providing-services.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/guides/providing-services.md b/guides/providing-services.md index 7021ce493..05ee068db 100644 --- a/guides/providing-services.md +++ b/guides/providing-services.md @@ -1139,10 +1139,9 @@ For bound actions and functions: ```ts async function srv.send ( - event : string | { event, entity, data?, params, headers? }, - entity : string, - data? : object | any, - params : array of any, + event : string | { event, entity, data?, params, headers? }, + entity : string, + data? : object | any ) return : result of this.dispatch(req) ``` @@ -1159,10 +1158,10 @@ Programmatic usage would look like this for Node.js: await srv.send('sum',{x:1,y:2}) await srv.send('add',{x:11,to:2}) await srv.send('stock',{id:2}) - // bound actions/functions + // actions/functions bound to collection await srv.send('getStock','Foo',{id:2}) - //for passing the params property, use this syntax - await srv.send({ event: 'order', entity: 'Foo', data: {x:3}, params: [2]}) + // for actions/functions bound to entity instance, use this syntax + await srv.send({ event: 'order', entity: 'Foo', data: {x:3}, params: [{id:2}]}) ``` > Note: Always pass the target entity name as second argument for bound actions/functions. From 306d44d6859098c3ed82699f71a18f0d538d1c37 Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Fri, 27 Jun 2025 11:19:43 +0200 Subject: [PATCH 07/10] review comments --- guides/providing-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/providing-services.md b/guides/providing-services.md index 05ee068db..999e3ca5c 100644 --- a/guides/providing-services.md +++ b/guides/providing-services.md @@ -1139,7 +1139,7 @@ For bound actions and functions: ```ts async function srv.send ( - event : string | { event, entity, data?, params, headers? }, + event : string | { event, entity, data?, params?: array of object, headers?: object }, entity : string, data? : object | any ) From 8808701783b00a916216cee773927fc697846719 Mon Sep 17 00:00:00 2001 From: Vitaly Kozyura <58591662+vkozyura@users.noreply.github.com> Date: Fri, 27 Jun 2025 13:35:05 +0200 Subject: [PATCH 08/10] review comment --- guides/providing-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/providing-services.md b/guides/providing-services.md index 999e3ca5c..705f9cf55 100644 --- a/guides/providing-services.md +++ b/guides/providing-services.md @@ -1129,7 +1129,7 @@ For unbound actions and functions: ```ts async function srv.send ( - event : string | { event, data?, headers? }, + event : string | { event, data?, headers?: object }, data? : object | any ) return : result of this.dispatch(req) From c1bceb939c700b060ee0cbca10afaa4d5d81e343 Mon Sep 17 00:00:00 2001 From: Mahati Shankar Date: Mon, 30 Jun 2025 16:44:13 +0200 Subject: [PATCH 09/10] cosmetics --- node.js/core-services.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/node.js/core-services.md b/node.js/core-services.md index a0f4aaded..82385bd56 100644 --- a/node.js/core-services.md +++ b/node.js/core-services.md @@ -799,9 +799,7 @@ Use this method to send synchronous requests to a service for execution. - `method` is an HTTP method - `path` can be an arbitrary URL, starting with a leading `'/'`, it is passed to a service without any modification as a string -For calling bound / unbound actions and functions from the service further variants of `srv.send` are additionally supported, -as described in the Section [Calling Actions / Functions](../guides/providing-services#calling-actions-functions). -Basically the action or function name to be used instead of the HTTP method. +To call bound / unbound actions and functions from the service further variants of `srv.send` are additionally supported, as described in the Section [Calling Actions / Functions](../guides/providing-services#calling-actions-functions). Basically, use the action or function name instead of the HTTP method. Examples: From f592c69ca008e4b82783dcf6e0b66f22884ba01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Jeglinsky?= Date: Tue, 1 Jul 2025 09:12:04 +0200 Subject: [PATCH 10/10] Update node.js/core-services.md --- node.js/core-services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.js/core-services.md b/node.js/core-services.md index 82385bd56..cfedbc359 100644 --- a/node.js/core-services.md +++ b/node.js/core-services.md @@ -799,7 +799,7 @@ Use this method to send synchronous requests to a service for execution. - `method` is an HTTP method - `path` can be an arbitrary URL, starting with a leading `'/'`, it is passed to a service without any modification as a string -To call bound / unbound actions and functions from the service further variants of `srv.send` are additionally supported, as described in the Section [Calling Actions / Functions](../guides/providing-services#calling-actions-functions). Basically, use the action or function name instead of the HTTP method. +To call bound / unbound actions and functions from the service, further variants of `srv.send` are additionally supported, as described in the section [Calling Actions / Functions](../guides/providing-services#calling-actions-functions). Basically, use the action or function name instead of the HTTP method. Examples: