### Install Dependencies and Start Application (Node.js) Source: https://github.com/capire/docs/blob/main/guides/security/authentication.md Install project dependencies and start the CAP application locally using npm. ```sh npm install cds up ``` -------------------------------- ### Clone and Run Bookshop Sample Source: https://github.com/capire/docs/blob/main/guides/integration/calesi.md Clone the bookshop sample repository and start the CAP server to begin integration examples. ```shell git clone https://github.com/capire/bookshop cds watch bookshop ``` -------------------------------- ### Capire Docs Development Server Output Example Source: https://github.com/capire/docs/blob/main/CONTRIBUTING.md Example output when starting the Capire documentation development server, showing the local URL. ```sh vitepress v1.0.0... ➜ Local: http://localhost:5173/ ``` -------------------------------- ### REPL Output Example Source: https://github.com/capire/docs/blob/main/node.js/cds-test.md Illustrates the typical output seen in the REPL upon loading the CAP model and starting the server. ```log [cds] - model loaded from 5 file(s): srv/cat-service.cds srv/admin-constraints.cds srv/admin-service.cds db/schema.cds node_modules/@sap/cds/common.cds [cds] - connect to db > sqlite { url: ':memory:' } > init from db/data/sap.capire.bookshop-Genres.csv > init from db/data/sap.capire.bookshop-Books.texts.csv > init from db/data/sap.capire.bookshop-Books.csv > init from db/data/sap.capire.bookshop-Authors.csv /> successfully deployed to sqlite in-memory db [cds] - serving AdminService { ... } [cds] - serving CatalogService {... } [cds] - server listening on { url: 'http://localhost:64914' } [cds] - launched at 9/8/2021, 5:36:20 PM, in: 767.042ms [ terminate with ^C ] ``` -------------------------------- ### CAP Server Output Example Source: https://github.com/capire/docs/blob/main/get-started/index.md Example output when `cds watch` starts serving a service. ```shell [cds] - loaded model from 1 file(s): srv/cat-service.cds [cds] - connect to db > sqlite { url: ':memory:' } [cds] - serving CatalogService { at: ['/odata/v4/catalog'] } [cds] - server listening on { url: 'http://localhost:4004' } ``` -------------------------------- ### Local Server Output Source: https://github.com/capire/docs/blob/main/README.md Example output when the local development server starts. ```sh vitepress v1... ➜ Local: http://localhost:5173/docs/ ➜ Network: use --host to expose ➜ press h to show help ``` -------------------------------- ### Initialize and Install Sample Project Source: https://github.com/capire/docs/blob/main/guides/integration/reuse-and-compose.md Initialize a new sample CAP project and install its dependencies. ```sh cds init sample --nodejs cd sample npm i ``` -------------------------------- ### Clone and Install Bookstore Sample Source: https://github.com/capire/docs/blob/main/guides/integration/reuse-and-compose.md Clone the bookstore sample repository and install its dependencies to prepare for exercises. ```sh git clone https://github.com/capire/bookstore cd bookstore npm install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/capire/docs/blob/main/README.md Start a local development server to view the documentation locally. ```sh npm run start ``` -------------------------------- ### Automated Deployment Steps Source: https://github.com/capire/docs/blob/main/guides/deploy/to-cf.md This section details the automated steps involved in building and deploying an application, including dependency installation, monorepo handling, multitenant sidecar setup, and final assembly. ```sh # Installing app dependencies, e.g. npm i app/browse npm i app/admin-books # If project is monorepo ln -sf ../package-lock.json # If project is multitenant npm i --package-lock-only --prefix mtx/sidecar # If package-lock.json doesn't exist npm i --package-lock-only # Final assembly and deployment... mbt build -t gen --mtar mta.tar cf deploy gen/mta.tar -f ``` -------------------------------- ### Install Java and Maven on Windows Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs SapMachine JDK using winget and downloads/installs Apache Maven manually, updating the system PATH. Verifies installation with `mvn -version`. ```powershell winget install --silent SAP.SapMachine.25.JDK # Apache Maven is not available using winget so download it directly $v="3.9.12"; ` $url="https://dlcdn.apache.org/maven/maven-3/$v/binaries/apache-maven-$v-bin.zip"; ` $mvnzip="$env:LOCALAPPDATA\maven.zip"; ` curl $url -o $mvnzip; ` tar -xf $mvnzip -C "$env:LOCALAPPDATA"; ` setx PATH "$env:PATH;$env:LOCALAPPDATA\apache-maven-$v\bin"; ` rm $mvnzip # Reload PATH from registry to access newly installed tools $env:PATH = [Environment]::GetEnvironmentVariable("PATH","Machine") ` + ";" + [Environment]::GetEnvironmentVariable("PATH","User") mvn -version # display Maven and Java versions # done ``` -------------------------------- ### Install Dependencies Source: https://github.com/capire/docs/blob/main/README.md Install the necessary dependencies for the documentation project. ```sh npm run setup ``` -------------------------------- ### Clone and install Bookshop sample (Node.js) Source: https://github.com/capire/docs/blob/main/get-started/bookshop.md Clones the ready-made bookshop sample project and installs its Node.js dependencies. ```shell git clone https://github.com/capire/bookshop npm install ``` -------------------------------- ### Start CAP Server with `cds-serve` Source: https://github.com/capire/docs/blob/main/node.js/cds-server.md Use this script in `package.json` to start a CAP server when the `@sap/cds-dk` package is not available. ```json { "scripts": { "start": "cds-serve" } } ``` -------------------------------- ### Clone and install Bookshop sample (Java) Source: https://github.com/capire/docs/blob/main/get-started/bookshop.md Clones the ready-made bookshop sample project and installs its Java dependencies using Maven. ```shell git clone https://github.com/sap-samples/cloud-cap-samples-java bookshop mvn install ``` -------------------------------- ### Mock Data Structures for Examples Source: https://github.com/capire/docs/blob/main/node.js/core-services.md Example of setting up mock data structures for Authors and Books entities, used in request handling examples. ```javascript Authors.data = { 111: { ID:111, name:'Emily Brontë' }, 112: { ID:112, name:'Edgar Allan Poe' }, 114: { ID:114, name:'Richard Carpenter' }, } Books.data = { 211: { ID:211, title:'Wuthering Heights', author: Authors.data[111], stock:11 }, 212: { ID:212, title:'Eleonora', author: Authors.data[112], stock:14 }, 214: { ID:214, title:'Catweazle', author: Authors.data[114], stock:114 }, } ``` -------------------------------- ### Start Main Application (Java Maven) Source: https://github.com/capire/docs/blob/main/guides/extensibility/feature-toggles.md Start the main Java application using the Maven command. ```sh mvn spring-boot:run ``` -------------------------------- ### Install Node.js and cds-dk on Windows Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Node.js LTS and SQLite using winget, then installs cds-dk globally via npm. Verifies installation with `cds -v` and `sqlite3 -version`. ```powershell # We use multiline console commands to improve usability in Windows PowerShell. # PowerShell will ask for confirmation when you paste these commands, adding an extra safety step. winget install --silent OpenJS.NodeJS.LTS winget install --silent SQLite.SQLite # Reload PATH from registry to access newly installed tools $env:PATH = [Environment]::GetEnvironmentVariable("PATH","Machine") ` + ";" + [Environment]::GetEnvironmentVariable("PATH","User") npm i -g @sap/cds-dk # install CAP's cds-dk globally cds -v # check cds version sqlite3 -version # done ``` -------------------------------- ### Install Java and Maven on macOS/Linux Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs SapMachine JDK and Apache Maven using Homebrew. ```shell brew install sapmachine-jdk brew install maven ``` -------------------------------- ### Install Visual Studio Code on Linux Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Visual Studio Code using snap. Verifies installation with `code -v`. ```bash # VS Code on Homebrew is only supported for macOS sudo snap install --classic code code -v # display VS Code's version ``` -------------------------------- ### Fetch Next Page of Records Source: https://github.com/capire/docs/blob/main/guides/services/served-ootb.md To retrieve the subsequent set of records after a truncation, clients should use the provided 'nextLink' URL in a follow-up GET request. This example shows fetching records starting from the token '1000'. ```http GET .../Books?$skiptoken=1000 ``` -------------------------------- ### Initialize and Run Sample Application (Java) Source: https://github.com/capire/docs/blob/main/guides/security/authentication.md Initializes a sample CAP application with Java backend and starts it using Maven. ```sh cds init bookshop --java --add sample && cd ./bookshop mvn spring-boot:run ``` -------------------------------- ### Getting CDS Installation Folder Source: https://github.com/capire/docs/blob/main/node.js/cds-facade.md Access the cds.home property in the cds repl to find the installation folder of the '@sap/cds' package. ```javascript [dev] cds repl > cds.home // [!code focus] ~/.npm/lib/node_modules/@sap/cds ``` -------------------------------- ### Install SQLite for Custom Configuration Source: https://github.com/capire/docs/blob/main/guides/databases/new-dbs.md Install the SQLite package when setting up a custom database configuration. ```sh npm add @cap-js/sqlite ``` -------------------------------- ### Initialize Project with Multitenancy and MTA Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-init.out.md Scaffolds a new project named 'bookshop' and adds support for multitenancy and MTA. ```bash cds init bookshop --add multitenancy,mta ``` -------------------------------- ### Avoiding Reserved Names Starting with '$' Source: https://github.com/capire/docs/blob/main/cds/compiler/v2.md Shows examples of using reserved names starting with '$' or '!' for entity definitions, which results in compiler warnings and should be avoided. ```cds entity $Funny { ... }; // this name should not be used entity ![$Too] { ... }; // this name should not be used ``` -------------------------------- ### Install Git CLI and GitHub CLI on Linux Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Git CLI and GitHub CLI using Homebrew. Includes steps to download and install GitHub Desktop from a .deb package. ```shell brew install git # Git CLI brew install gh # GitHub CLI # Github-Desktop on Homebrew is only supported for macOS GHD_VERSION="3.3.12" GHD_HOST="https://github.com/shiftkey/desktop/releases/download" curl -L ${GHD_HOST}/release-${GHD_VERSION}-linux1/ GitHubDesktop-linux-amd64-${GHD_VERSION}-linux1.deb -o github-desktop.deb sudo apt install ./github-desktop.deb rm ./github-desktop.deb ``` -------------------------------- ### npm ls Output Example Source: https://github.com/capire/docs/blob/main/guides/integration/inner-loops.md Example output of 'npm ls @capire/xflights-data' showing the local link to the xflights-data service. ```zsh samples@ ~/cap/samples ├── @capire/xflights-data@0.1.11 -> ./xflights/apis/data-service └─┬ @capire/xtravels@1.0.0 -> ./xtravels └── @capire/xflights-data@0.1.11 deduped -> ./xflights/apis/data-service ``` -------------------------------- ### OData GET Request for Navigation Source: https://github.com/capire/docs/blob/main/guides/services/consuming-services.md Example of an OData GET request to navigate from a 'Risks' entity to its associated 'supplier' entity using the association name. ```http GET /service/risks/Risks(20466922-7d57-4e76-b14c-e53fd97dcb11)/supplier ``` -------------------------------- ### Initialize Java Project Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-init.out.md Scaffolds a new project named 'bookshop' with Java runtime. ```bash cds init bookshop --java ``` -------------------------------- ### Optimistic Locking: GET Request with If-None-Match Source: https://github.com/capire/docs/blob/main/guides/services/served-ootb.md Example of a GET request using the If-None-Match header to check if a resource has been modified. A 304 Not Modified response indicates no changes. ```http GET Employees/111 If-None-Match: "2000-01-01T01:10:10.100Z" > 304 Not Modified // Record was not changed ``` -------------------------------- ### Initialize and Run Sample Application (Node.js) Source: https://github.com/capire/docs/blob/main/guides/security/authentication.md Initializes a sample CAP application with Node.js backend and starts it using cds watch. ```sh cds init bookshop --nodejs --add sample && cd ./bookshop cds watch ``` -------------------------------- ### Optimistic Locking: GET Request with If-Match Source: https://github.com/capire/docs/blob/main/guides/services/served-ootb.md Example of a GET request using the If-Match header. A 412 Precondition Failed response indicates the record was changed by another user. ```http GET Employees/111 If-Match: "2000-01-01T01:10:10.100Z" > 412 Precondition Failed // Record was changed by another user ``` -------------------------------- ### Initialize and Watch a CAP Project Source: https://github.com/capire/docs/blob/main/get-started/features.md Use these commands to quickly set up a new CAP project and start the development server. This is the recommended way to begin developing CAP applications. ```sh cds init cds watch ``` -------------------------------- ### REST Request Example Source: https://github.com/capire/docs/blob/main/java/building-plugins.md Illustrates a sample HTTP GET request to a CatalogService to retrieve a book by its ID. ```http GET /CatalogService/Books?id=100 ``` -------------------------------- ### Initialize Node.js Project Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-init.out.md Scaffolds a new project named 'bookshop' with Node.js runtime. ```bash cds init bookshop --nodejs ``` -------------------------------- ### Initialize Project with SAP HANA Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-init.out.md Scaffolds a new project named 'bookshop' and adds SAP HANA support. ```bash cds init bookshop --add hana ``` -------------------------------- ### Install Homebrew on Linux Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Homebrew on Linux, including necessary prerequisites like curl and git. ```shell # install curl (required to get Homebrew) and git (required to run Homebrew) sudo apt install curl git -y bash -c "$( curl https://raw.githubusercontent.com/homebrew/install/HEAD/install.sh )" ``` -------------------------------- ### Initialize Node.js Project with Sample and HANA Source: https://github.com/capire/docs/blob/main/tools/cds-cli.md Create a new Node.js project using `cds init` with sample data and HANA configuration by specifying `--nodejs --add sample,hana`. ```sh cds init --nodejs --add sample,hana ``` -------------------------------- ### Poll Job Status Source: https://github.com/capire/docs/blob/main/guides/multitenancy/mtxs.md Example HTTP GET request to poll the status of an asynchronous job using its task ID. ```http GET /-/cds/jobs/pollTask(ID='') HTTP/1.1 ``` -------------------------------- ### Starting a CDS Server for Testing Source: https://github.com/capire/docs/blob/main/node.js/cds-test.md Shows how to start a CDS server for testing using cds.test() with different argument patterns, including specifying files, services, or target folders. ```javascript cds.test(...) ``` ```javascript (new cds.test.Test).run(...) ``` ```javascript cds.test('serve','srv/cat-service.cds') cds.test('serve','CatalogService') ``` ```javascript cds.test('serve','srv/cat-service.cds').in('/cap/samples/bookshop') ``` ```javascript cds.test('/cap/samples/bookshop') ``` ```javascript cds.test('serve','all','--in-memory?').in('/cap/samples/bookshop') cds.test().in('/cap/samples/bookshop') //> equivalent ``` -------------------------------- ### Write OData tests with cds.test Source: https://github.com/capire/docs/blob/main/node.js/cds-test.md Example of writing OData tests using cds.test, including setting defaults and making GET requests. ```js const cds = require ('@sap/cds') const { GET, expect, defaults } = cds.test ('@capire/bookshop') defaults.auth = { username: 'alice' } defaults.path = '/odata/v4/browse' describe ('browse books', ()=>{ it ('should allow fetching lists of books', async () => { const { data } = await GET `Books? $select=ID,title` expect (data.value) .to.deep.equal ( [ { ID: 201, title: 'Wuthering Heights' }, { ID: 207, title: 'Jane Eyre' }, { ID: 251, title: 'The Raven' }, { ID: 252, title: 'Eleonora' }, { ID: 271, title: 'Catweazle' }, ] ) }) //... }) ``` -------------------------------- ### Install Node.js and cds-dk on macOS/Linux Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Node.js LTS and the SAP CAP cds-dk globally using Homebrew and npm. ```shell brew install node # Node.js LTS npm i -g @sap/cds-dk # install CAP's cds-dk globally ``` -------------------------------- ### SELECT.from with Query-by-Example Key Source: https://github.com/capire/docs/blob/main/node.js/cds-ql.md Shows how to use SELECT.from with a query-by-example object to specify the key for fetching records. ```javascript SELECT.from (Books,201) //> shortcut for {ID:201} SELECT.from (Books, {ID:201}) SELECT.from (Books.texts, {ID:201, locale:'de'}) ``` -------------------------------- ### Get All Extensions Response Source: https://github.com/capire/docs/blob/main/guides/multitenancy/mtxs.md Example JSON response for retrieving all tenant-specific extensions. Each entry includes the extension ID, compiled CSN, and timestamp. ```json [ { "ID": "isbn-extension", "csn": "{\"extensions\":[{\"extend\":\"my.bookshop.Books\",\"elements\":{\"Z_ISBN\":{\"type\":\"cds.String\"}}}],\"definitions\":{}}", "timestamp": "2023-01-01T01:01:01.111Z" }, { "ID": "rental-extension", "csn": "{\"extensions\":[{\"extend\":\"my.bookshop.Books\",\"elements\":{\"Z_rentalPrice\":{\"type\":\"cds.Integer\"}}}],\"definitions\":{}}", "timestamp": "2023-01-01T01:02:01.111Z" } ] ``` -------------------------------- ### Get Specific Extension Response Source: https://github.com/capire/docs/blob/main/guides/multitenancy/mtxs.md Example JSON response for retrieving a specific tenant-specific extension, including its ID, compiled CSN, and timestamp. ```json { "ID": "isbn-extension", "csn": "{\"extensions\":[{\"extend\":\"my.bookshop.Books\",\"elements\":{\"Z_ISBN\":{\"type\":\"cds.String\"}}}],\"definitions\":{}}", "timestamp": "2023-01-01T01:01:01.111Z" } ``` -------------------------------- ### Serve All Defined Services Source: https://github.com/capire/docs/blob/main/node.js/core-services.md Illustrates the bootstrapping logic using `cds.serve` to create and serve instances of defined services. ```javascript cds.app = require('express')() const csn = await cds.load('*') cds.model = cds.compile.for.nodejs(csn) cds.services = await cds.serve('all').from(cds.model).in(cds.app) ``` -------------------------------- ### Bookstore Service Trace Output Source: https://github.com/capire/docs/blob/main/guides/events/messaging.md Example trace output when starting the 'bookstore' service, showing connection to the 'ReviewsService' and use of file-based messaging. ```log [cds] - connect to messaging > file-based-messaging { file: '~/.cds-msg-box' } [cds] - mocking OrdersService { path: '/orders', impl: '../orders/srv/orders-service.js' } [cds] - serving CatalogService { path: '/browse', impl: '../reviews/srv/cat-service.js' } [cds] - serving AdminService { path: '/admin', impl: '../reviews/srv/admin-service.js' } [cds] - connect to ReviewsService > odata { url: 'http://localhost:4005/reviews' } [cds] - server listening on { url: 'http://localhost:4004' } [cds] - launched at 5/25/2023, 4:55:46 PM, version: 7.0.0, in: 1.053s ``` -------------------------------- ### Reviews Service Trace Output Source: https://github.com/capire/docs/blob/main/guides/events/messaging.md Example trace output when starting the 'reviews' service, indicating the use of file-based messaging and the service path. ```log [cds] - connect to messaging > file-based-messaging { file: '~/.cds-msg-box' } [cds] - serving ReviewsService { path: '/reviews', impl: '../reviews/srv/reviews-service.js' } [cds] - server listening on { url: 'http://localhost:4005' } [cds] - launched at 5/25/2023, 4:53:46 PM, version: 7.0.0, in: 593.274ms ``` -------------------------------- ### CAP Server Trace Output Source: https://github.com/capire/docs/blob/main/guides/events/core-concepts.md This is an example of the trace output when a CAP server starts. It shows which services are mocked and served, and the listening URL. ```log [cds] - mocking ReviewsService { path: '/reviews', impl: '../reviews/srv/reviews-service.js' } [cds] - mocking OrdersService { path: '/orders', impl: '../orders/srv/orders-service.js' } [cds] - serving CatalogService { path: '/browse', impl: '../bookshop/srv/cat-service.js' } [cds] - serving AdminService { path: '/admin', impl: '../bookshop/srv/admin-service.js' } [cds] - server listening on { url: 'http://localhost:4004' } [cds] - launched at 5/25/2023, 4:53:46 PM, version: 7.0.0, in: 991.573ms ``` -------------------------------- ### Correct CDS Schema with Lowercase Element Source: https://github.com/capire/docs/blob/main/tools/cds-lint/rules/start-elements-lowercase/index.md This example demonstrates a correct CDS schema where the element 'title' starts with a lowercase letter, satisfying the rule. ```cds namespace my.bookshop; entity Books { key ID : UUID; title : localized String(111); stock : Integer; } ``` -------------------------------- ### JavaBeans Style Accessor Methods Source: https://github.com/capire/docs/blob/main/java/developing-applications/building.md Example demonstrating the use of getter and setter methods prefixed with 'get' and 'set' for data access, inspired by JavaBeans. ```java Authors author = Authors.create(); author.setName("Emily Brontë"); Books book = Books.create(); book.setAuthor(author); book.setTitle("Wuthering Heights"); ``` -------------------------------- ### Initialize Project and Add Services (Java) Source: https://github.com/capire/docs/blob/main/guides/deploy/to-kyma.md Initializes a new CAP project with Java runtime and adds HANA and XSUAA services. ```sh cds init bookshop --java --add sample && cd bookshop cds add hana,xsuaa ``` -------------------------------- ### Incorrect CDS Schema with Uppercase Element Source: https://github.com/capire/docs/blob/main/tools/cds-lint/rules/start-elements-lowercase/index.md This example shows an incorrect CDS schema where the element 'Title' starts with an uppercase letter, triggering a warning from the rule. ```cds namespace my.bookshop; entity Books { key ID : UUID; Title : localized String(111); stock : Integer; } ``` -------------------------------- ### Get CDS CLI Version Source: https://github.com/capire/docs/blob/main/tools/cds-cli.md Use `cds version` to display the installed version of the CDS Development Kit. For markdown output, use the `--markdown` flag. ```sh cds version ``` ```sh cds version --markdown ``` -------------------------------- ### SELECT.columns Examples Source: https://github.com/capire/docs/blob/main/node.js/cds-ql.md Demonstrates various syntaxes for specifying columns in a SELECT statement, including using projection functions, tagged template strings, and direct CQL/CQN expressions. ```sql SELECT.from `Books` .columns (b => { b.title, b.author.name.as('author') }) SELECT.from `Books` .columns `{ title, author.name as author }` SELECT.from `Books` .columns `title, author.name as author` SELECT.from `Books` .columns ( 'title', 'author.name as author') SELECT.from `Books` .columns ( 'title', {ref:['author','name'],as:'author'} ) SELECT.from `Books` .columns (['title', {ref:['author','name'],as:'author'} ]) ``` -------------------------------- ### Injecting Services as Spring Beans Source: https://github.com/capire/docs/blob/main/java/services.md Use Spring's dependency injection to get access to service objects within a component. This example injects generic interfaces. ```java @Component public class EventHandlerClass implements EventHandler { @Autowired private PersistenceService db; @Autowired @Qualifier("AdminService") private ApplicationService adminService; } ``` -------------------------------- ### Initialize Project and Add Services (Node.js) Source: https://github.com/capire/docs/blob/main/guides/deploy/to-kyma.md Initializes a new CAP project with Node.js runtime and adds HANA and XSUAA services. ```sh cds init bookshop --nodejs --add sample && cd bookshop cds add hana,xsuaa ``` -------------------------------- ### MTX Sidecar Service Startup Log Source: https://github.com/capire/docs/blob/main/guides/multitenancy/mtxs.md Example log output when the MTX sidecar starts successfully, indicating the services it's serving and the port it's listening on. ```log cd mtx/sidecar cds serve all --with-mocks --in-memory? live reload enabled for browsers ___________________________ [cds] - loaded model from 3 file(s): ../cds-mtxs/srv/model-provider.cds ../cds-mtxs/srv/deployment-service.cds ../cds-mtxs/db/t0.cds [cds] - connect using bindings from: { registry: '~/.cds-services.json' } [cds] - connect to db > sqlite { url: '../../db.sqlite' } [cds] - using authentication: { kind: 'mocked' } [cds] - serving cds.xt.ModelProviderService { path: '/-/cds/model-provider' } [cds] - serving cds.xt.DeploymentService { path: '/-/cds/deployment' } [cds] - loaded model from 1 file(s): ../cds-mtxs/db/t0.cds [mtx] - (re-)deploying SQLite database for tenant: t0 /> successfully deployed to db-t0.sqlite [cds] - server listening on { url: 'http://localhost:4005' } // [!code highlight] [cds] - launched at 5/6/2023, 1:08:33 AM, version: 7.3.0, in: 772.25ms [cds] - [ terminate with ^C ] ``` -------------------------------- ### HTTP Requests for Actions/Functions Source: https://github.com/capire/docs/blob/main/guides/services/custom-actions.md Examples of how to call unbound and bound actions/functions using HTTP GET and POST requests. It also notes conventions for function calls and bound operations. ```APIDOC ## Calling Actions / Functions via HTTP ### Description Examples of HTTP requests to call unbound and bound actions/functions. ### Unbound Actions/Functions #### GET .../sue/sum(x=1,y=2) Calls the unbound function 'sum' with parameters x and y. #### GET .../sue/stock(id=2) Calls the unbound function 'stock' with parameter id. #### POST .../sue/add {"x":11,"to":2} Calls the unbound action 'add' with parameters x and to in the request body. ### Bound Actions/Functions #### GET .../sue/Foo(2)/Sue.getStock() Calls the bound function 'getStock' on entity 'Foo' with ID 2. Requires service name prefix. #### POST .../sue/Foo(2)/Sue.order {"x":3} Calls the bound action 'order' on entity 'Foo' with ID 2. Requires service name prefix and request body. ### Notes - Always add `()` for functions, even if no arguments are required. - Bound actions/functions may need to be prefixed with the service name (e.g., `Sue.getStock`). - For convenience, unbound actions/functions can use query parameters (e.g., `sue/sum?x=1&y=2`). ``` -------------------------------- ### Log Entry for Deployment Version Source: https://github.com/capire/docs/blob/main/java/outbox.md A log entry at startup indicates the configured `application.deployment.version`. ```bash 2024-12-19T11:21:33.253+01:00 INFO 3420 --- [main] cds.services.impl.utils.BuildInfo : application.deployment.version: 1.0.0-SNAPSHOT ``` -------------------------------- ### Substring in Predicate Source: https://github.com/capire/docs/blob/main/java/working-with-cql/query-api.md Uses the `substring` function within a predicate to test if a portion of a string matches a given value. This example checks if the string starting from the third character equals 'ter'. ```java Select.from("bookshop.Authors") .where(e -> e.get("name").substring(2).eq("ter")); ``` -------------------------------- ### Timeless Model Definition Source: https://github.com/capire/docs/blob/main/guides/domain/temporal-data.md Defines a base model for managing employees, work assignments, and departments without temporal data management. This serves as a starting point for temporal data examples. ```cds namespace com.acme.hr; using { com.acme.common.Persons } from './common'; entity Employees : Persons { jobs : Composition of many WorkAssignments on jobs.empl=$self; job1 : Association to one /*of*/ WorkAssignments; } entity WorkAssignments { key ID : UUID; role : String(111); empl : Association to Employees; dept : Association to Departments; } entity Departments { key ID : UUID; name : String(111); head : Association to Employees; members : Association to many Employees on members.jobs.dept = $self; } ``` -------------------------------- ### Create Proxy Files using Here Document Source: https://github.com/capire/docs/blob/main/guides/integration/inner-loops.md Demonstrates creating the package.json and index.cds files for the proxy package using the shell's 'here document' technique. ```shell cat > xflights-api-shortcut/package.json << EOF { "name": "@capire/xflights-data", "dependencies": { "@capire/xflights": "*" } } EOF ``` ```shell cat > xflights-api-shortcut/index.cds << EOF using from '@capire/xflights/srv/data-service'; EOF ``` -------------------------------- ### Install Git, GitHub CLI, and GitHub Desktop on Windows Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Git, GitHub CLI, and GitHub Desktop using winget. Verifies Git CLI version. ```powershell winget install --silent Git.Git winget install --silent GitHub.cli winget install --silent GitHub.GitHubDesktop # Reload PATH from registry to access newly installed tools $env:PATH = [Environment]::GetEnvironmentVariable("PATH","Machine") ` + ";" + [Environment]::GetEnvironmentVariable("PATH","User") git -v # display Git cli version # done ``` -------------------------------- ### Define Complex Projections with Lambda Expressions Source: https://github.com/capire/docs/blob/main/java/working-with-cql/query-api.md Use lambda expressions for more complex projections and to benefit from code completion. This example shows how to get the title and author's name, aliasing the latter. ```java // dynamic Select.from("bookshop.Books") .columns(b -> b.get("title"), b -> b.get("author.name").as("authorName")); ``` ```java // static import static bookshop.Bookshop_.BOOKS; Select.from(BOOKS) .columns(b -> b.title(), b -> b.author().name().as("authorName")); ``` -------------------------------- ### Find Annotation and Get Value Source: https://github.com/capire/docs/blob/main/java/reflection-api.md Programmatically find an annotation on a CDS element and retrieve its value. This example checks for the 'title' annotation on the 'OrderNo' element of the 'Orders' entity and sets a display name. ```java CdsEntity order = model.getEntity("my.bookshop.Orders"); CdsElement orderNo = order.getElement("OrderNo"); Optional> annotation = orderNo .findAnnotation("title"); String displayName = annotation.map(CdsAnnotation::getValue) .orElse(orderNo.getName()); // "Order Number" ``` -------------------------------- ### Test HTTP Methods (get, put, post) Source: https://github.com/capire/docs/blob/main/node.js/cds-test.md Mirrored versions of corresponding methods from axios, prefixing requests with the started server's URL and port. These methods use the Fetch API under the hood. ```APIDOC ### test. get/put/post/...() {#http-methods .method} ### Description These are mirrored versions of the corresponding [methods from `axios`](https://github.com/axios/axios#instance-methods), which prefix each request with the started server's url and port, which simplifies your test code. ### Method GET, POST ### Endpoint `/browse/Books` `/browse/submitOrder` ### Parameters #### Query Parameters - **auth** (object) - Optional - Authentication details for the request, e.g., `{ username: 'alice', password: '...' }`. ### Request Example ```js const test = cds.test() //> served at localhost with an arbitrary port const { data } = await test.get('/browse/Books') await test.post('/browse/submitOrder', { book:201, quantity:1 }, { auth: { username: 'alice' }}) ``` ### Response #### Success Response (200) - **data** (any) - The response data from the server. ``` -------------------------------- ### Add CDS Lint Setup Source: https://github.com/capire/docs/blob/main/tools/cds-lint/index.md Installs ESLint, the CDS ESLint plugin, and adds ESLint configuration to your project. This command also adds VS Code settings for linting CDS alongside other languages. ```sh cds add lint ``` -------------------------------- ### Start Capire Docs Development Server Source: https://github.com/capire/docs/blob/main/CONTRIBUTING.md Starts the local development server for Capire documentation. Changes to content are immediately reflected. ```sh npm run docs:dev ``` -------------------------------- ### Sample HTTP Servlet Adapter Implementation Source: https://github.com/capire/docs/blob/main/java/building-plugins.md An example of a custom protocol adapter extending HttpServlet. This adapter handles incoming HTTP requests, maps them to CQL statements, and executes them using the CdsRuntime. ```java public class SampleAdapter extends HttpServlet { private final CdsRuntime runtime; public SampleAdapter(CdsRuntime runtime) { this.runtime = runtime; // see below for further details } @Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { // see below for further details } } ``` -------------------------------- ### Display CAP CDS Version Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-version.out.md Run this command in your terminal to view the installed versions of the CAP CDS development kit and its associated packages. This helps in verifying your setup and identifying potential version conflicts. ```bash > cds version @sap/cds-dk (global) 9.9.1 .../node_modules/@sap/cds-dk @sap/cds 9.9.1 .../node_modules/@sap/cds @sap/cds-compiler 6.9.2 .../node_modules/@sap/cds-compiler @sap/cds-fiori 2.3.0 .../node_modules/@sap/cds-fiori @cap-js/db-service 2.11.0 .../node_modules/@cap-js/db-service @cap-js/sqlite 2.4.0 .../node_modules/@cap-js/sqlite cds.home .../node_modules/@sap/cds cds.root .../your-project npm root -l .../node_modules npm root -g .../node_modules Node.js 24.16.0 .../bin/node ``` -------------------------------- ### Install HTTP Client and Resilience SDKs Source: https://github.com/capire/docs/blob/main/guides/deploy/microservices.md Installs necessary SAP Cloud SDK packages for HTTP client and resilience features in the bookstore workspace. ```shell npm i @sap-cloud-sdk/http-client --workspace bookstore npm i @sap-cloud-sdk/resilience --workspace bookstore ``` -------------------------------- ### Override OData Type Mapping for UUID Source: https://github.com/capire/docs/blob/main/guides/protocols/odata.md Override the default mapping for the CDS type UUID, which normally maps to Edm.Guid. This example maps it to Edm.String to accommodate OData's restrictive Guid format rules. ```cds entity Books { key ID : UUID @odata.Type:'Edm.String'; // ... } ``` -------------------------------- ### Customizing Helmet Content Security Policy Source: https://github.com/capire/docs/blob/main/node.js/best-practices.md This example shows how to customize the Content Security Policy (CSP) provided by the Helmet middleware. It merges default directives with custom settings for enhanced security. Ensure Helmet is installed. ```javascript cds.on('bootstrap', app => { app.use( helmet({ contentSecurityPolicy: { directives: { ...helmet.contentSecurityPolicy.getDefaultDirectives() // custom settings } } }) ) }) ``` -------------------------------- ### Start CAP Server Source: https://github.com/capire/docs/blob/main/guides/events/core-concepts.md Run this command to start a CAP application with all-in-one server process. It mocks required services and serves defined application services. ```sh cds watch bookstore ``` -------------------------------- ### Registering to Lifecycle Events (Simplified) Source: https://github.com/capire/docs/blob/main/node.js/cds-server.md A simplified example showing how to register handlers for CAP server bootstrapping lifecycle events using `cds.on()`. ```javascript const cds = require('@sap/cds') cds.on('bootstrap', ...) cds.on('served', ...) cds.on('listening', ...) ``` -------------------------------- ### Handle Unknown Tenant Errors in Multitenant Setup Source: https://github.com/capire/docs/blob/main/java/messaging.md Extend the custom error handler to specifically manage errors related to unknown tenants in a multitenant environment. This example shows how to access tenant information and message details. ```java @On(service = "messaging") private void handleError(MessagingErrorEventContext ctx) { String errorCode = ctx.getException().getErrorStatus().getCodeString(); if (errorCode.equals(CdsErrorStatuses.NO_ON_HANDLER.getCodeString()) || errorCode.equals(CdsErrorStatuses.INVALID_DATA_FORMAT.getCodeString())) { // error handling for infrastructure error ctx.setResult(false); // no acknowledgement } else if (errorCode.equals(CdsErrorStatuses.TENANT_NOT_EXISTS.getCodeString())) { // error handling for unknown tenant context // tenant of the received message String tenant = ctx.getTenant(); // received message Map headers = ctx.getMessageHeaders(); Map message = ctx.getMessageData(); ctx.setResult(true); // acknowledge } else { // error handling for application errors // how to access the event context of the raised exception: // ctx.getException().getEventContexts().stream().findFirst().ifPresent(e -> { // TopicMessageEventContext errorContext = e.as(TopicMessageEventContext.class); // String event = e.getEvent()); // Map payload = errorContext.getDataMap(); // }); ctx.setResult(true); // acknowledge } } ``` -------------------------------- ### HTTP Bound Methods (GET, PUT, POST) Source: https://github.com/capire/docs/blob/main/node.js/cds-test.md Provides bound variants of test methods for making HTTP requests to a started CDS server. Supports tagged template string style for single URL arguments and includes options for authentication. ```APIDOC ## GET / PUT / POST ... {#http-bound .method} ### Description These are bound variants of the [`test.get/put/post/...` methods](#http-methods) allowing to write HTTP requests. ### Method GET, PUT, POST ### Endpoint `/browse/Books` `/browse/submitOrder` ### Parameters #### Query Parameters - **auth** (object) - Optional - Authentication details for the request, e.g., `{ username: 'alice', password: '...' }`. ### Request Example ```js const { GET, POST } = cds.test() const { data } = await GET('/browse/Books') await POST('/browse/submitOrder', { book:201, quantity:1 }, { auth: { username: 'alice' }}) ``` ### Response #### Success Response (200) - **data** (any) - The response data from the server. ``` -------------------------------- ### Compile All Services to EDMX with Output Directory Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-compile.out.md Compiles all services to EDMX format and directs the output to a specified directory. The '-s all' option selects all services, '-l all' applies all languages, '-2 edmx' specifies EDMX as the target format, and '-o' sets the output directory. ```bash cds srv -s all -l all -2 edmx -o [4mout ``` -------------------------------- ### Initialize CAP Project Source: https://github.com/capire/docs/blob/main/guides/uis/vue-react.md Initializes a new CAP project with Node.js and a tiny sample, then opens it in the code editor. ```sh cds init bookshop --add nodejs,tiny-sample && code bookshop ``` -------------------------------- ### Inspect Element Type of an Entity Source: https://github.com/capire/docs/blob/main/java/reflection-api.md Introspect the details of an element's type within a CDS entity. This example shows how to get the 'title' element from 'my.bookshop.Books' and inspect its properties like key, localization, type name, base type, Java type, and length. ```java CdsEntity books = model.getEntity("my.bookshop.Books"); CdsElement title = books.getElement("title"); boolean key = title.isKey(); // false boolean localized = title.isLocalized(); // true CdsType type = title.getType(); // CdsSimpleType if (type.isSimple()) { // true CdsSimpleType simple = type.as(CdsSimpleType.class); String typeName = simple.getQualifiedName(); // "cds.String" CdsBaseType baseType = simple.getType(); // CdsBaseType.STRING Class javaType = simple.getJavaType(); // String.class Integer length = simple.get("length"); // 111 } ``` -------------------------------- ### Suppress GET (by-key) but allow GET (list) Source: https://github.com/capire/docs/blob/main/guides/protocols/openapi.md This JSON snippet disables only by-key GET requests for an entity set while keeping list GET requests enabled. ```json "@Capabilities.ReadRestrictions": { "ReadByKeyRestrictions": { "Readable": false } } ``` -------------------------------- ### Configuring Log Levels in package.json Source: https://github.com/capire/docs/blob/main/node.js/cds-log.md Demonstrates how to set initial log levels for specific modules ('sql', 'cds') within the package.json configuration. ```json { "cds": { "log": { "levels": { "sql": "debug", "cds": "info" } } } } ``` -------------------------------- ### Suppress GET (list) but allow GET (by-key) Source: https://github.com/capire/docs/blob/main/guides/protocols/openapi.md This JSON snippet disables only list GET requests for an entity set while keeping by-key GET requests enabled. ```json "@Capabilities.ReadRestrictions": { "Readable": false, "ReadByKeyRestrictions": { "Readable": true } } ``` -------------------------------- ### Clone and Setup Capire Docs Locally Source: https://github.com/capire/docs/blob/main/CONTRIBUTING.md Clone the Capire documentation repository and set up the local development environment. Requires Node.js version 18 or higher. ```sh git clone https://github.com/cap-js/docs capire cd capire npm run setup ``` -------------------------------- ### Install Homebrew on macOS Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Homebrew, a package manager for macOS, which is recommended for managing installations. ```shell bash -c "$( curl https://raw.githubusercontent.com/homebrew/install/HEAD/install.sh )" ``` -------------------------------- ### Initialize Java Project with Maven Parameters Source: https://github.com/capire/docs/blob/main/tools/assets/help/cds-init.out.md Scaffolds a new Java project using the Maven archetype, specifying group ID, artifact ID, and package name. ```bash cds init --java --java:mvn DgroupId=myGroup,DartifactId=newId,Dpackage=my.company ``` -------------------------------- ### Initialize a new CDS-based project Source: https://github.com/capire/docs/blob/main/get-started/feature-matrix.md Use `cds init` to create a new project structure for a CAP application. ```bash cds init ``` -------------------------------- ### Initialize Java CAP Project Source: https://github.com/capire/docs/blob/main/guides/deploy/to-cf.md Initializes a new CAP project with Java runtime and adds sample data. ```sh cds init bookshop --java --add sample cd bookshop ``` -------------------------------- ### Start App Router with CDS Bind (PowerShell) Source: https://github.com/capire/docs/blob/main/node.js/authentication.md Starts the App Router using 'cds bind --exec' in PowerShell. This command binds services and starts the npm start script for the router. ```powershell cds bind --exec '--' npm start --prefix app/router ``` -------------------------------- ### Start Sidecar (Shell) Source: https://github.com/capire/docs/blob/main/guides/extensibility/feature-toggles.md Start the sidecar in a separate shell before starting the main application, as the main app depends on the sidecar. ```sh cds watch mtx/sidecar ``` -------------------------------- ### Initialize Basic Node.js or Java Project Source: https://github.com/capire/docs/blob/main/tools/cds-cli.md Initialize a basic Node.js or Java project using `cds init` with the `--nodejs` or `--java` flags respectively. ```sh cds init --nodejs ``` ```sh cds init --java ``` -------------------------------- ### Start App Router with CDS Bind (macOS/Linux) Source: https://github.com/capire/docs/blob/main/node.js/authentication.md Starts the App Router using 'cds bind --exec' on macOS or Linux. This command binds services and starts the npm start script for the router. ```sh cds bind --exec -- npm start --prefix app/router ``` -------------------------------- ### Initialize Node.js CAP Project Source: https://github.com/capire/docs/blob/main/guides/deploy/to-cf.md Initializes a new CAP project with Node.js runtime and adds sample data. ```sh cds init bookshop --nodejs --add sample cd bookshop ``` -------------------------------- ### Install Visual Studio Code on Windows Source: https://github.com/capire/docs/blob/main/get-started/index.md Installs Visual Studio Code using winget. Verifies installation with `code -v`. ```powershell winget install --silent Microsoft.VisualStudioCode # Reload PATH from registry to access newly installed tools $env:PATH = [Environment]::GetEnvironmentVariable("PATH","Machine") ` + ";" + [Environment]::GetEnvironmentVariable("PATH","User") code -v # display VS Code's version # done ```