diff --git a/.registry/.gitignore b/.registry/.gitignore new file mode 100644 index 00000000..aa1ec1ea --- /dev/null +++ b/.registry/.gitignore @@ -0,0 +1 @@ +*.tgz diff --git a/.registry/server.js b/.registry/server.js index c1461016..2696d948 100644 --- a/.registry/server.js +++ b/.registry/server.js @@ -5,15 +5,15 @@ const app = express() const { PORT=4444 } = process.env const [,,port=PORT] = process.argv +const cwd = __dirname app.use('/-/:tarball', (req,res,next) => { - const url = decodeURIComponent(req.url) console.debug ('GET', req.params) try { const { tarball } = req.params const [, pkg ] = /^capire-(\w+)/.exec(tarball) fs.lstat(tarball,(err => { - if (err) exec(`npm pack ../${pkg}`,next) + if (err) exec(`npm pack ../${pkg}`,{cwd},next) else next() })) } catch (e) { diff --git a/.tours/db-native.tour b/.tours/db-native.tour new file mode 100644 index 00000000..035ef298 --- /dev/null +++ b/.tours/db-native.tour @@ -0,0 +1,109 @@ +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "Database Functions", + "steps": [ + { + "title": "Introduction", + "description": "### Database Functions in CDS Models\n\nIn this tour, you'll learn how to add database-specific functions to CDS models in your application." + }, + { + "file": "bookshop/db/schema.cds", + "description": "#### Basic Schema\n\nWe want to add two fields to the `Authors` entity, one for the author's age and one for the span of years that she or he lived.\n\nThese two fields can be computed out of the existing `dateOfBirth` and `dateOfDeath` fields.", + "selection": { + "start": { + "line": 19, + "character": 1 + }, + "end": { + "line": 21, + "character": 1 + } + }, + "title": "Base fields in Author" + }, + { + "file": "bookshop/srv/admin-service.cds", + "description": "This is how the `Authors` entity gets exposed in an OData or REST service.\n\nIn the next step, you'll see how we extend this projection.", + "selection": { + "start": { + "line": 4, + "character": 1 + }, + "end": { + "line": 5, + "character": 1 + } + }, + "title": "Authors service" + }, + { + "file": "fiori/db/sqlite/index.cds", + "description": "#### SQLite Implementation\n\nHere's the first implementation for SQLite. It computes the two fields `age` and `lifetime` through SQLite's [strftime](https://sqlite.org/lang_datefunc.html) function.\n\nThrough the [`extend projection`](https://cap.cloud.sap/docs/cds/cdl#extend-view) clause you can add additional fields to projection entities. These are deployed as database views, which is why we can integrate the database functions in the first place.\n", + "selection": { + "start": { + "line": 7, + "character": 1 + }, + "end": { + "line": 11, + "character": 1 + } + }, + "title": "SQLite implementation" + }, + { + "file": "fiori/db/hana/index.cds", + "description": "#### SAP HANA Implementation\n\nThis is the second implementation for SAP HANA. It computes the same two fields `age` and `lifetime` through the [YEARS_BETWEEN](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/7c0d2c161ea34def86de3f5eadd6a0af.html) and [YEAR](https://help.sap.com/viewer/7c78579ce9b14a669c1f3295b0d8ca16/Cloud/en-US/20f5fac6751910148dabd3c6821f907d.html) functions of SAP HANA.\n\n#### File Layout and Code Structure\n\nNote the path of the `.cds` file we are in: it's in a subfolder of `db`, so that it's _not_ automatically picked up when we start the application. The same is true for the SQLite implementation: it's in a separate `db/sqlite/` folder as well. In the next step, you'll see how these files are loaded.\n\nAlso, we choose to implement all of that as an extension of the original bookshop here in the _fiori_ package. See the first [CAP Samples] code tour for more details on the different packages of this repository.", + "selection": { + "start": { + "line": 7, + "character": 1 + }, + "end": { + "line": 11, + "character": 1 + } + }, + "title": "SAP HANA implementation" + }, + { + "file": "fiori/package.json", + "description": "#### Configuration\n\nThe `cds` section in `package.json` is a place to configure which of the `db/sqlite` and `db/hana` folders are used for which database.\nWe use [Node.js profiles](https://cap.cloud.sap/docs/node.js/cds-env#profiles) to separate the configuration.\nIn the `development` profile, you can see that `db/sqlite` is set as the model, while the `db/hana` folder is configured in the `production` profile.", + "line": 17, + "title": "Configuration" + }, + { + "file": "fiori/package.json", + "description": "#### Run with SQLite\n\nTo run with `development` and an in-memory SQLite database, you don't need to do anything special, because it's activated by default. Just run:\n\n>> cds watch fiori\n\nThen open [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) to see the two new fields.\n", + "line": 28, + "title": "Run with SQLite" + }, + { + "file": "fiori/package.json", + "description": "#### Deploy the CDS Model to SAP HANA\n\nTo 'activate' SAP HANA through the `production` profile, you can use the global `--production` flag:\n\n>> cd fiori; cds deploy --to hana --production\n\n[Learn more about SAP HANA deployment](https://cap.cloud.sap/docs/guides/databases#get-hana)\n\n#### Run the Application\n\n>> cd fiori; cds watch --production\n\nThe service on [http://localhost:4004/admin/Authors](http://localhost:4004/admin/Authors) is the same as before, but this time the `Authors` entity is backed by a database view with an SAP HANA function.\n\n#### More\n\nIf you don't see data, you can add some in the next step.", + "line": 31, + "title": "Run with SAP HANA" + }, + { + "file": "fiori/test/requests.http", + "description": "### Add More Data\n\nOptionally you can add some `Authors` data by clicking on the _Send Request_ link (provided by the [REST client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension).", + "line": 68, + "selection": { + "start": { + "line": 67, + "character": 1 + }, + "end": { + "line": 73, + "character": 1 + } + }, + "title": "Add Data" + }, + { + "title": "Wrap-up", + "description": "### Summary\n\nThat's it! You have seen: \n- How to integrate database-specific functions in a CDS model.\n- How to switch between the two implementations for SQLite and SAP HANA." + } + ], + "ref": "master" +} \ No newline at end of file diff --git a/.tours/samples.tour b/.tours/samples.tour new file mode 100644 index 00000000..b3a15c28 --- /dev/null +++ b/.tours/samples.tour @@ -0,0 +1,136 @@ +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "CAP Samples", + "steps": [ + { + "title": "Welcome", + "file": "README.md", + "description": "### Welcome to CAP Samples!\n\nThis tour leads you through a collection of samples for the [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap).\nYou will learn which features of the programming model are demonstrated in which sample.\n\nLet's start!", + "line": 2, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 3, + "character": 108 + } + } + }, + { + "file": "hello/world.cds", + "description": "### Hello World!\n\nThis is a simplistic [Hello World](https://cap.cloud.sap/docs/get-started/hello-world) service using [CDS](https://cap.cloud.sap/docs/cds/) and [cds.services](https://cap.cloud.sap/docs/node.js/api#services-api).", + "line": 2, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 4, + "character": 1 + } + }, + "title": "Hello World!" + }, + { + "file": "bookshop/db/schema.cds", + "description": "### A Bookshop!\n\nIntroduces:\n- [Project Setup](https://cap.cloud.sap/docs/get-started/) and [Layouts](https://cap.cloud.sap/docs/get-started/projects)\n- [Domain Modeling](https://cap.cloud.sap/docs/guides/domain-models)\n- [Defining Services](https://cap.cloud.sap/docs/guides/providing-services)\n- [Generic Providers](https://cap.cloud.sap/docs/guides/generic-providers)\n- [Adding Custom Logic](https://cap.cloud.sap/docs/guides/service-impl)\n- [Using Databases](https://cap.cloud.sap/docs/guides/databases)\n", + "line": 1, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 32, + "character": 1 + } + }, + "title": "Bookshop" + }, + { + "file": "common/index.cds", + "description": "### Extend and Reuse\n\nShowcases how to extend [@sap/cds/common](https://cap.cloud.sap/docs/cds/common) thereby covering:\n- Building [extension packages](https://cap.cloud.sap/docs/guides/domain-models#aspects-extensibility)\n- Providing [reuse packages](https://cap.cloud.sap/docs/get-started/projects#sharing-and-reusing-content)\n- [Verticalization](https://cap.cloud.sap/docs/cds/common#adapting-to-your-needs)\n- Using [Aspects](https://cap.cloud.sap/docs/cds/cdl#aspects)\n- Used in the [fiori app sample](#fiori)\n", + "line": 1, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 46, + "character": 1 + } + }, + "title": "Common" + }, + { + "file": "orders/db/schema.cds", + "description": "### Compositions and Serving Documents\n\nA standalone orders management service, demonstrating:\n- Using [Compositions](https://cap.cloud.sap/docs/cds/cdl#compositions) in [Domain Models](https://cap.cloud.sap/docs/guides/domain-models), along with\n- [Serving deeply nested documents](https://cap.cloud.sap/docs/guides/generic-providers#serving-structured-data)\n", + "line": 1, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 27, + "character": 1 + } + }, + "title": "Orders" + }, + { + "file": "reviews/db/schema.cds", + "description": "### More Modularity\n\nShows how to implement a modular service to manage product reviews, including:\n- Consuming other services synchronously and asynchronously\n- Serving requests synchronously\n- Emitting events asynchronously\n- Grow as you go, with:\n- Mocking app services\n- Running service meshes\n- Late-cut Micro Services\n- As well as managed data, input validations, and authorization\n", + "line": 1, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 39, + "character": 1 + } + }, + "title": "Reviews" + }, + { + "file": "fiori/app/index.cds", + "description": "### Annotations for SAP Fiori Elements\n\nA [composite app, reusing and combining](https://cap.cloud.sap/docs/guides/verticalize) these packages:\n - [@capire/bookshop](bookshop)\n - [@capire/reviews](reviews)\n - [@capire/orders](orders)\n - [@capire/common](common)\n\n[Adds a SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to:\n - [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files\n - Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft)\n - Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help)\n - Serving SAP Fiori apps locally\n\n[The Vue.js app](bookshop/app/vue) imported from bookshop is served as well.\n", + "line": 1, + "selection": { + "start": { + "line": 1, + "character": 1 + }, + "end": { + "line": 13, + "character": 1 + } + }, + "title": "Fiori" + }, + { + "file": "package.json", + "description": "### All-in-one Monorepo\n\nEach sample sub directory essentially is a standard npm package, some with standard npm dependencies to other samples. The root folder's [package.json](package.json) has local links to the sub folders, such that an `npm install` populates a local `node_modules` folder acts like a local npm registry to the individual sample packages.\n", + "line": 8, + "selection": { + "start": { + "line": 8, + "character": 1 + }, + "end": { + "line": 15, + "character": 1 + } + }, + "title": "Packages" + } + ], + "isPrimary": true, + "description": "Overview of CAP Samples for Node.js" +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 240b1cf9..23f34ec2 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,14 +4,15 @@ // List of extensions which should be recommended for users of this workspace. "recommendations": [ - "SAPSE.vscode-cds", + "sapse.vscode-cds", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "mechatroner.rainbow-csv", "humao.rest-client", "alexcvzz.vscode-sqlite", "hbenl.vscode-mocha-test-adapter", - "sdras.night-owl" + "sdras.night-owl", + "vsls-contrib.codetour" ], // List of extensions recommended by VS Code that should not be recommended for users of this workspace. "unwantedRecommendations": [ diff --git a/.vscode/launch.json b/.vscode/launch.json index ad51dcef..40b41090 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,28 +4,31 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "name": "Attach by Process ID", - "processId": "${command:PickProcess}", - "request": "attach", - "skipFiles": [ - "/**" - ], - "type": "pwa-node" - }, { "name": "bookshop", - "command": "cds watch bookshop", - "request": "launch", + "command": "npx cds watch bookshop", "type": "node-terminal", - "skipFiles": ["/**"] + "request": "launch", + "skipFiles": [ + "/**", + "**/node_modules/**", + "**/cds/lib/lazy.js", + "**/cds/lib/req/cls.js", + "**/odata-v4/okra/**" + ] }, { - "name": "Fiori app", - "command": "cds watch fiori", - "request": "launch", + "name": "Fiori App", + "command": "npx cds watch fiori", "type": "node-terminal", - "skipFiles": ["/**"] + "request": "launch", + "skipFiles": [ + "/**", + "**/node_modules/**", + "**/cds/lib/lazy.js", + "**/cds/lib/req/cls.js", + "**/odata-v4/okra/**" + ] } ], "inputs": [ @@ -33,7 +36,7 @@ "type": "pickString", "id": "sample", "description": "Which sample do you want to start?", - "options": ["bookshop", "fiori", "reviews", "reviews/test/bookshop"], + "options": [ "bookshop", "fiori", "reviews", "reviews" ], "default": "bookshop" } ] diff --git a/.vscode/settings.json b/.vscode/settings.json index 72bc8cb5..1ca4aeaf 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,17 @@ { "files.exclude": { + ".reuse/**": true, "**/.gitignore": true, - "**/.vscode": true + "**/.vscode": true, + "LICENSES/**": true + }, + "debug.javascript.terminalOptions": { + "skipFiles": [ + "/**", + "**/node_modules/**", + "**/cds/lib/lazy.js", + "**/cds/lib/req/cls.js", + "**/odata-v4/okra/**" + ] } } diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4ed90b95..00000000 --- a/LICENSE +++ /dev/null @@ -1,208 +0,0 @@ -Apache License - -Version 2.0, January 2004 - -http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, -AND DISTRIBUTION - - 1. Definitions. - - - -"License" shall mean the terms and conditions for use, reproduction, and distribution -as defined by Sections 1 through 9 of this document. - - - -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. - - - -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct -or indirect, to cause the direction or management of such entity, whether -by contract or otherwise, or (ii) ownership of fifty percent (50%) or more -of the outstanding shares, or (iii) beneficial ownership of such entity. - - - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions -granted by this License. - - - -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. - - - -"Object" form shall mean any form resulting from mechanical transformation -or translation of a Source form, including but not limited to compiled object -code, generated documentation, and conversions to other media types. - - - -"Work" shall mean the work of authorship, whether in Source or Object form, -made available under the License, as indicated by a copyright notice that -is included in or attached to the work (an example is provided in the Appendix -below). - - - -"Derivative Works" shall mean any work, whether in Source or Object form, -that is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative -Works shall not include works that remain separable from, or merely link (or -bind by name) to the interfaces of, the Work and Derivative Works thereof. - - - -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative -Works thereof, that is intentionally submitted to Licensor for inclusion in -the Work by the copyright owner or by an individual or Legal Entity authorized -to submit on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication -sent to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor -for the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." - - - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently incorporated -within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this -License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, -no-charge, royalty-free, irrevocable copyright license to reproduce, prepare -Derivative Works of, publicly display, publicly perform, sublicense, and distribute -the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, -each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, -no-charge, royalty-free, irrevocable (except as stated in this section) patent -license to make, have made, use, offer to sell, sell, import, and otherwise -transfer the Work, where such license applies only to those patent claims -licensable by such Contributor that are necessarily infringed by their Contribution(s) -alone or by combination of their Contribution(s) with the Work to which such -Contribution(s) was submitted. If You institute patent litigation against -any entity (including a cross-claim or counterclaim in a lawsuit) alleging -that the Work or a Contribution incorporated within the Work constitutes direct -or contributory patent infringement, then any patent licenses granted to You -under this License for that Work shall terminate as of the date such litigation -is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or -Derivative Works thereof in any medium, with or without modifications, and -in Source or Object form, provided that You meet the following conditions: - -(a) You must give any other recipients of the Work or Derivative Works a copy -of this License; and - -(b) You must cause any modified files to carry prominent notices stating that -You changed the files; and - -(c) You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source -form of the Work, excluding those notices that do not pertain to any part -of the Derivative Works; and - -(d) If the Work includes a "NOTICE" text file as part of its distribution, -then any Derivative Works that You distribute must include a readable copy -of the attribution notices contained within such NOTICE file, excluding those -notices that do not pertain to any part of the Derivative Works, in at least -one of the following places: within a NOTICE text file distributed as part -of the Derivative Works; within the Source form or documentation, if provided -along with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents -of the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works -that You distribute, alongside or as an addendum to the NOTICE text from the -Work, provided that such additional attribution notices cannot be construed -as modifying the License. - -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, -or distribution of Your modifications, or for any such Derivative Works as -a whole, provided Your use, reproduction, and distribution of the Work otherwise -complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any -Contribution intentionally submitted for inclusion in the Work by You to the -Licensor shall be under the terms and conditions of this License, without -any additional terms or conditions. Notwithstanding the above, nothing herein -shall supersede or modify the terms of any separate license agreement you -may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, -trademarks, service marks, or product names of the Licensor, except as required -for reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to -in writing, Licensor provides the Work (and each Contributor provides its -Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied, including, without limitation, any warranties -or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR -A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness -of using or redistributing the Work and assume any risks associated with Your -exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether -in tort (including negligence), contract, or otherwise, unless required by -applicable law (such as deliberate and grossly negligent acts) or agreed to -in writing, shall any Contributor be liable to You for damages, including -any direct, indirect, special, incidental, or consequential damages of any -character arising as a result of this License or out of the use or inability -to use the Work (including but not limited to damages for loss of goodwill, -work stoppage, computer failure or malfunction, or any and all other commercial -damages or losses), even if such Contributor has been advised of the possibility -of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work -or Derivative Works thereof, You may choose to offer, and charge a fee for, -acceptance of support, warranty, indemnity, or other liability obligations -and/or rights consistent with this License. However, in accepting such obligations, -You may act only on Your own behalf and on Your sole responsibility, not on -behalf of any other Contributor, and only if You agree to indemnify, defend, -and hold each Contributor harmless for any liability incurred by, or claims -asserted against, such Contributor by reason of your accepting any such warranty -or additional liability. END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own identifying -information. (Don't include the brackets!) The text should be enclosed in -the appropriate comment syntax for the file format. We also recommend that -a file or class name and description of purpose be included on the same "printed -page" as the copyright notice for easier identification within third-party -archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); - -you may not use this file except in compliance with the License. - -You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software - -distributed under the License is distributed on an "AS IS" BASIS, - -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - -See the License for the specific language governing permissions and - -limitations under the License. diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..1653b640 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 38e5cef7..16ee56f1 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ Find here a collection of samples for the [SAP Cloud Application Programming Model](https://cap.cloud.sap) organized in a simplistic [monorepo setup](samples.md#all-in-one-monorepo). → See [**Overview** of contained samples](samples.md) ![](https://github.com/SAP-samples/cloud-cap-samples/workflows/CI/badge.svg) - - +[![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/cloud-cap-samples)](https://api.reuse.software/info/github.com/SAP-samples/cloud-cap-samples) ### Preliminaries @@ -18,7 +17,7 @@ Find here a collection of samples for the [SAP Cloud Application Programming Mod ### Download -If you have [Git](https://git-scm.com/downloads) installed, clone this repo as shown below, otherwise [download as ZIP file](archive/master.zip). +If you've [Git](https://git-scm.com/downloads) installed, clone this repo as shown below, otherwise [download as ZIP file](archive/master.zip). ```sh git clone https://github.com/sap-samples/cloud-cap-samples samples @@ -72,12 +71,16 @@ npm add @capire/common @capire/bookshop ``` +## Code Tours + +Take one of the [guided tours](.tours) in VS Code through our CAP samples and learn which CAP features are showcased by the different parts of the repository. Just install the [CodeTour extension](https://marketplace.visualstudio.com/items?itemName=vsls-contrib.codetour) for VS Code. We'll add more code tours in the future. Stay tuned! + ## Get Support Check out the documentation at [https://cap.cloud.sap](https://cap.cloud.sap).
-In case you have a question, find a bug, or otherwise need support, please use our [community](https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce). +In case you've a question, find a bug, or otherwise need support, use our [community](https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce) to get more visibility. ## License -Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSES/Apache-2.0.txt) file. +Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE.txt) file. diff --git a/bookshop/app/index.cds b/bookshop/app/services.cds similarity index 100% rename from bookshop/app/index.cds rename to bookshop/app/services.cds diff --git a/bookshop/app/vue/app.js b/bookshop/app/vue/app.js index 78bd342b..f99d87a8 100644 --- a/bookshop/app/vue/app.js +++ b/bookshop/app/vue/app.js @@ -35,7 +35,7 @@ const books = new Vue ({ try { const res = await POST(`/submitOrder`, { amount, book: book.ID }) book.stock = res.data.stock - books.order = { amount, succeeded: `Successfully orderd ${amount} item(s).` } + books.order = { amount, succeeded: `Successfully ordered ${amount} item(s).` } } catch (e) { books.order = { amount, failed: e.response.data.error.message } } diff --git a/bookshop/app/vue/index.html b/bookshop/app/vue/index.html index 56c79a07..c8e23209 100644 --- a/bookshop/app/vue/index.html +++ b/bookshop/app/vue/index.html @@ -36,7 +36,7 @@ {{ ('★'.repeat(Math.round(book.rating))+'☆☆☆☆☆').slice(0,5) }} - {{ book.currency.symbol }} {{ book.price }} + {{ book.currency && book.currency.symbol }} {{ book.price }} diff --git a/bookshop/db/data/sap.capire.bookshop-Books.csv b/bookshop/db/data/sap.capire.bookshop-Books.csv index cb3044aa..702375bb 100644 --- a/bookshop/db/data/sap.capire.bookshop-Books.csv +++ b/bookshop/db/data/sap.capire.bookshop-Books.csv @@ -3,4 +3,4 @@ ID;title;descr;author_ID;stock;price;currency_code;genre_ID 207;Jane Eyre;"Jane Eyre /ɛər/ (originally published as Jane Eyre: An Autobiography) is a novel by English writer Charlotte Brontë, published under the pen name ""Currer Bell"", on 16 October 1847, by Smith, Elder & Co. of London. The first American edition was published the following year by Harper & Brothers of New York. Primarily a bildungsroman, Jane Eyre follows the experiences of its eponymous heroine, including her growth to adulthood and her love for Mr. Rochester, the brooding master of Thornfield Hall. The novel revolutionised prose fiction in that the focus on Jane's moral and spiritual development is told through an intimate, first-person narrative, where actions and events are coloured by a psychological intensity. The book contains elements of social criticism, with a strong sense of Christian morality at its core and is considered by many to be ahead of its time because of Jane's individualistic character and how the novel approaches the topics of class, sexuality, religion and feminism.";107;11;12.34;GBP;11 251;The Raven;"""The Raven"" is a narrative poem by American writer Edgar Allan Poe. First published in January 1845, the poem is often noted for its musicality, stylized language, and supernatural atmosphere. It tells of a talking raven's mysterious visit to a distraught lover, tracing the man's slow fall into madness. The lover, often identified as being a student, is lamenting the loss of his love, Lenore. Sitting on a bust of Pallas, the raven seems to further distress the protagonist with its constant repetition of the word ""Nevermore"". The poem makes use of folk, mythological, religious, and classical references.";150;333;13.13;USD;16 252;Eleonora;"""Eleonora"" is a short story by Edgar Allan Poe, first published in 1842 in Philadelphia in the literary annual The Gift. It is often regarded as somewhat autobiographical and has a relatively ""happy"" ending.";150;555;14;USD;16 -271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;15;EUR;13 \ No newline at end of file +271;Catweazle;Catweazle is a British fantasy television series, starring Geoffrey Bayldon in the title role, and created by Richard Carpenter for London Weekend Television. The first series, produced and directed by Quentin Lawrence, was screened in the UK on ITV in 1970. The second series, directed by David Reid and David Lane, was shown in 1971. Each series had thirteen episodes, most but not all written by Carpenter, who also published two books based on the scripts.;170;22;150;JPY;13 \ No newline at end of file diff --git a/bookshop/package.json b/bookshop/package.json index c2f3c081..ff55612a 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -4,7 +4,7 @@ "description": "A simple self-contained bookshop service.", "dependencies": { "@capire/common": "*", - "@sap/cds": "^4", + "@sap/cds": "^5.0.4", "cors": "^2.8.5", "express": "^4.17.1", "passport": "0.4.1" diff --git a/bookshop/srv/cat-service.cds b/bookshop/srv/cat-service.cds index f6fb00cd..4cc44dff 100644 --- a/bookshop/srv/cat-service.cds +++ b/bookshop/srv/cat-service.cds @@ -1,13 +1,15 @@ using { sap.capire.bookshop as my } from '../db/schema'; service CatalogService @(path:'/browse') { - @readonly entity Books as SELECT from my.Books { *, + /** For displaying lists of Books */ + @readonly entity ListOfBooks as projection on Books + excluding { descr }; + + /** For display in details pages */ + @readonly entity Books as projection on my.Books { *, author.name as author } excluding { createdBy, modifiedBy }; - @readonly entity ListOfBooks as SELECT from Books - excluding { descr }; - @requires: 'authenticated-user' action submitOrder ( book: Books:ID, amount: Integer ) returns { stock: Integer }; event OrderedBook : { book: Books:ID; amount: Integer; buyer: String }; diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 4676dcd5..a27aa397 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -5,10 +5,10 @@ class CatalogService extends cds.ApplicationService { init(){ // Reduce stock of ordered books if available stock suffices this.on ('submitOrder', async req => { - const {book,amount} = req.data, tx = cds.tx(req) - let {stock} = await tx.read('stock').from(Books,book) + const {book,amount} = req.data + let {stock} = await SELECT `stock` .from (Books,book) if (stock >= amount) { - await tx.update (Books,book).with ({ stock: stock -= amount }) + await UPDATE (Books,book) .with (`stock -=`, amount) await this.emit ('OrderedBook', { book, amount, buyer:req.user.id }) return { stock } } @@ -16,10 +16,8 @@ class CatalogService extends cds.ApplicationService { init(){ }) // Add some discount for overstocked books - this.after ('READ','Books', each => { - if (each.stock > 111) { - each.title += ` -- 11% discount!` - } + this.after ('READ','ListOfBooks', each => { + if (each.stock > 111) each.title += ` -- 11% discount!` }) return super.init() diff --git a/common/data/sap.common-Currencies_texts.csv b/common/data/sap.common-Currencies_texts.csv index 4d2ead51..4c46cefd 100644 --- a/common/data/sap.common-Currencies_texts.csv +++ b/common/data/sap.common-Currencies_texts.csv @@ -5,9 +5,11 @@ CAD;de;Kanadischer Dollar;Kanadischer Dollar AUD;de;Australischer Dollar;Australischer Dollar GBP;de;Pfund;Britische Pfund ILS;de;Schekel;Israelische Schekel +JPY;de;Yen;Japanische Yen EUR;fr;euro;de la Zone euro USD;fr;dollar;dollar des États-Unis CAD;fr;dollar canadien;dollar canadien AUD;fr;dollar australien;dollar australien GBP;fr;livre sterling;pound sterling -ILS;fr;Shekel;shekel israelien \ No newline at end of file +ILS;fr;Shekel;shekel israelien +JPY;fr;Yen;Yen japonais \ No newline at end of file diff --git a/common/package.json b/common/package.json index c1998c24..35e537aa 100644 --- a/common/package.json +++ b/common/package.json @@ -3,6 +3,6 @@ "description": "Provides a pre-built extension package for std @sap/cds/common", "version": "1.0.0", "dependencies": { - "@sap/cds": "latest" + "@sap/cds": "*" } } diff --git a/fiori/app/_i18n/i18n.properties b/fiori/app/_i18n/i18n.properties index c1d0293f..83681bcf 100644 --- a/fiori/app/_i18n/i18n.properties +++ b/fiori/app/_i18n/i18n.properties @@ -11,6 +11,7 @@ DateOfBirth = Date of Birth DateOfDeath = Date of Death PlaceOfBirth = Place of Birth PlaceOfDeath = Place of Death +Age = Age Authors = Authors Order = Order Orders = Orders diff --git a/fiori/app/_i18n/i18n_de.properties b/fiori/app/_i18n/i18n_de.properties index 365b45df..7724f685 100644 --- a/fiori/app/_i18n/i18n_de.properties +++ b/fiori/app/_i18n/i18n_de.properties @@ -6,6 +6,7 @@ Authors = Autoren Author = Autor AuthorID = ID des Autors AuthorName = Name des Autors +Age = Alter Name = Name Stock = Bestand Order = Bestellung diff --git a/fiori/app/admin/fiori-service.cds b/fiori/app/admin/fiori-service.cds index 1aeddb9f..d1c2b50a 100644 --- a/fiori/app/admin/fiori-service.cds +++ b/fiori/app/admin/fiori-service.cds @@ -1,4 +1,4 @@ -using AdminService from '@capire/bookshop'; +using { AdminService } from '../../db/schema'; //////////////////////////////////////////////////////////////////////////// // @@ -39,6 +39,27 @@ annotate AdminService.Books with @( } ); +annotate AdminService.Authors with @( + UI: { + HeaderInfo: { + Description: {Value: lifetime} + }, + Facets: [ + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'}, + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Books}', Target: 'books/@UI.LineItem'}, + ], + FieldGroup#Details: { + Data: [ + {Value: placeOfBirth}, + {Value: placeOfDeath}, + {Value: dateOfBirth}, + {Value: dateOfDeath}, + {Value: age, Label: '{i18n>Age}'}, + ] + }, + } +); + //////////////////////////////////////////////////////////// @@ -49,7 +70,7 @@ annotate AdminService.Books with @( annotate sap.capire.bookshop.Books with @fiori.draft.enabled; annotate AdminService.Books with @odata.draft.enabled; -annotate AdminService.Books_texts with @( +annotate AdminService.Books.texts with @( UI: { Identification: [{Value:title}], SelectionFields: [ locale, title ], @@ -62,7 +83,7 @@ annotate AdminService.Books_texts with @( ); // Add Value Help for Locales -annotate AdminService.Books_texts { +annotate AdminService.Books.texts { locale @ValueList:{entity:'Languages',type:#fixed} } // In addition we need to expose Languages through AdminService diff --git a/fiori/app/bookshop.html b/fiori/app/bookshop.html index 13c22ac5..e7c07e25 100644 --- a/fiori/app/bookshop.html +++ b/fiori/app/bookshop.html @@ -1,3 +1,3 @@ - + diff --git a/fiori/app/common.cds b/fiori/app/common.cds index 614f03b3..b609498d 100644 --- a/fiori/app/common.cds +++ b/fiori/app/common.cds @@ -54,7 +54,7 @@ annotate my.Books with { title @title:'{i18n>Title}'; genre @title:'{i18n>Genre}' @Common: { Text: genre.name, TextArrangement: #TextOnly }; author @title:'{i18n>Author}' @Common: { Text: author.name, TextArrangement: #TextOnly }; - price @title:'{i18n>Price}'; + price @title:'{i18n>Price}' @Measures.ISOCurrency: currency_code; stock @title:'{i18n>Stock}'; descr @UI.MultiLineText; } diff --git a/fiori/app/reviews.html b/fiori/app/reviews.html index a74f6c74..75af8860 100644 --- a/fiori/app/reviews.html +++ b/fiori/app/reviews.html @@ -1,3 +1,3 @@ - + diff --git a/fiori/app/index.cds b/fiori/app/services.cds similarity index 100% rename from fiori/app/index.cds rename to fiori/app/services.cds diff --git a/fiori/db/hana/index.cds b/fiori/db/hana/index.cds new file mode 100644 index 00000000..04822ad0 --- /dev/null +++ b/fiori/db/hana/index.cds @@ -0,0 +1,10 @@ +// +// Add Author.age and .lifetime with a DB-specific function +// + +using { AdminService } from '../schema'; + +extend projection AdminService.Authors with { + YEARS_BETWEEN(dateOfBirth, dateOfDeath) as age: Integer, + YEAR(dateOfBirth) || ' – ' || YEAR(dateOfDeath) as lifetime : String +} diff --git a/fiori/db/schema.cds b/fiori/db/schema.cds new file mode 100644 index 00000000..479fdbfb --- /dev/null +++ b/fiori/db/schema.cds @@ -0,0 +1,8 @@ +using { sap.capire.bookshop } from '@capire/bookshop'; + +// Forward-declare calculated fields to be filled in database-specific ways +// TODO find a better way to have 'default' fields that still can be overwritten. +extend bookshop.Authors with { + virtual age: Integer; + virtual lifetime: String; +} diff --git a/fiori/db/sqlite/index.cds b/fiori/db/sqlite/index.cds new file mode 100644 index 00000000..019335ef --- /dev/null +++ b/fiori/db/sqlite/index.cds @@ -0,0 +1,10 @@ +// +// Add Author.age and .lifetime with a DB-specific function +// + +using { AdminService } from '../schema'; + +extend projection AdminService.Authors with { + strftime('%Y',dateOfDeath)-strftime('%Y',dateOfBirth) as age: Integer, + strftime('%Y',dateOfBirth) || ' – ' || strftime('%Y',dateOfDeath) as lifetime : String +} diff --git a/fiori/package.json b/fiori/package.json index a4028d2e..2e4e62cf 100644 --- a/fiori/package.json +++ b/fiori/package.json @@ -6,25 +6,39 @@ "@capire/reviews": "*", "@capire/orders": "*", "@capire/common": "*", - "@sap/cds": "^4", + "@sap/cds": "^5", "express": "^4.17.1", - "passport": "0.4.1" + "passport": "^0.4.1" }, "scripts": { "start": "cds run --in-memory?", "watch": "cds watch" }, "cds": { + "hana": { + "deploy-format": "hdbtable" + }, "requires": { + "auth": { + "strategy": "dummy" + }, "ReviewsService": { - "kind": "odata", "model": "@capire/reviews" + "kind": "odata", + "model": "@capire/reviews" }, "OrdersService": { - "kind": "odata", "model": "@capire/orders" + "kind": "odata", + "model": "@capire/orders" }, "db": { - "kind": "sql" + "kind": "sql", + "[development]": { + "model": "db/sqlite" + }, + "[production]": { + "model": "db/hana" + } } } } -} \ No newline at end of file +} diff --git a/fiori/server.js b/fiori/server.js index 887190f9..a8dc4298 100644 --- a/fiori/server.js +++ b/fiori/server.js @@ -1,19 +1,18 @@ -const express = require ('express') const cds = require ('@sap/cds') cds.once('bootstrap',(app)=>{ - const {dirname} = require ('path') - // serving the orders app imported from @capire/orders - const orders_app = dirname (require.resolve('@capire/orders/app/orders/webapp/manifest.json')) - app.use ('/orders/webapp', express.static(orders_app)) - // serving the vue.js app imported from @capire/bookshop - const bookshop_app = dirname (require.resolve('@capire/bookshop/app/vue/index.html')) - app.use ('/vue/bookshop', express.static(bookshop_app)) - // serving the vue.js app imported from @capire/reviews - const reviews_app = dirname (require.resolve('@capire/reviews/app/vue/index.html')) - app.use ('/vue/reviews', express.static(reviews_app)) + app.use ('/orders/webapp', _from('@capire/orders/app/orders/webapp/manifest.json')) + app.use ('/bookshop', _from('@capire/bookshop/app/vue/index.html')) + app.use ('/reviews', _from('@capire/reviews/app/vue/index.html')) }) cds.once('served', require('./srv/mashup')) module.exports = cds.server + + +// ----------------------------------------------------------------------- +// Helper for serving static content from npm-installed packages +const {static} = require('express') +const {dirname} = require('path') +const _from = target => static (dirname (require.resolve(target))) diff --git a/fiori/test/requests.http b/fiori/test/requests.http index 95076ce3..d8392583 100644 --- a/fiori/test/requests.http +++ b/fiori/test/requests.http @@ -38,7 +38,11 @@ GET {{bookshop}}/browse/Books(201)? &$select=ID,title,rating &$expand=reviews +### +GET {{bookshop}}/browse/Books? + &$select=title,author&$expand=currency +Accept-Language: de ################################################# # @@ -63,3 +67,15 @@ Content-Type: application/json ### Get active order GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=true) + +### Create author +POST {{bookshop}}/admin/Authors +Content-Type: application/json +Authorization: Basic alice: + +{ + "ID": 200, + "name": "William Shakespeare", + "dateOfBirth": "1564-04-26", + "dateOfDeath": "1616-04-23" +} diff --git a/orders/db/schema.cds b/orders/db/schema.cds index c3b4f1c5..0911a4c4 100644 --- a/orders/db/schema.cds +++ b/orders/db/schema.cds @@ -13,7 +13,7 @@ entity Orders_Items { up_ : Association to Orders; product : Association to Products @assert.integrity:false; // REVISIT: this is a temporary workaround for a glitch in cds-runtime amount : Integer; - title : String; + title : String; //> intentionally replicated as snapshot from product.title price : Double; } @@ -21,6 +21,3 @@ entity Orders_Items { entity Products @(cds.persistence.skip:'always') { key ID : String; } - -// Activate extension package -using from '@capire/common'; diff --git a/orders/package.json b/orders/package.json index e1c683af..7415f469 100644 --- a/orders/package.json +++ b/orders/package.json @@ -2,7 +2,6 @@ "name": "@capire/orders", "version": "1.0.0", "dependencies": { - "@capire/common": "*", - "@sap/cds": "^4.3.0" + "@sap/cds": "^5" } } \ No newline at end of file diff --git a/package.json b/package.json index af1ea777..a756611e 100644 --- a/package.json +++ b/package.json @@ -17,16 +17,17 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "chai-subset": "^1.6.0", - "sqlite3": "5.0.0", + "sqlite3": "^5.0.0", "swagger-ui-express": "^4.1.4" }, "scripts": { - "registry": "cd .registry && node server.js", + "cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules", + "registry": "node .registry/server.js", "bookshop": "cds watch bookshop", "fiori": "cds watch fiori", "media": "cds watch media", "mocha": "npx mocha || echo", - "jest": "npx jest", + "jest": "npx jest@^26", "test": "npm run jest --silent" }, "mocha": { diff --git a/reviews/package.json b/reviews/package.json index 970b956c..b91edfba 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -7,7 +7,7 @@ "index.cds" ], "dependencies": { - "@sap/cds": "^4", + "@sap/cds": "^5", "express": "^4.17.1" }, "scripts": { diff --git a/reviews/readme.md b/reviews/readme.md index 5574f752..2fe87b4e 100644 --- a/reviews/readme.md +++ b/reviews/readme.md @@ -2,20 +2,23 @@ ## Run all-in-one -Open a terminal window and run the bookshop in it: +Open a terminal window and run the `fiori` app in it: + ```sh -npm run bookshop +npm run fiori ``` -## Run as separate services +## Run as Separate Services + +Open two terminal windows. In the first one start the reviews service stand-alone: -Open two terminal windows, and in the first one start the reviews service stand-alone: ```sh npm run reviews-service ``` -In the the second one start the bookshop: +In the second one start the `fiori` app: + ```sh -npm run bookshop +npm run fiori ``` diff --git a/reviews/srv/reviews-service.cds b/reviews/srv/reviews-service.cds index eb26d9ae..6e026b99 100644 --- a/reviews/srv/reviews-service.cds +++ b/reviews/srv/reviews-service.cds @@ -17,7 +17,7 @@ service ReviewsService { annotate Reviews with { subject @mandatory; title @mandatory; - rating @assert.enum; + rating @assert.range; } } diff --git a/samples.md b/samples.md index bc5f7f81..cf9a60b4 100644 --- a/samples.md +++ b/samples.md @@ -57,14 +57,13 @@ Each sub directory essentially is an individual npm package arranged in an [all- - [@capire/reviews](reviews) - [@capire/orders](orders) - [@capire/common](common) -- [Adds a SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to: +- [Adds an SAP Fiori elements application](https://cap.cloud.sap/docs/guides/fiori/) to bookshop, thereby introducing to: - [OData Annotations](https://cap.cloud.sap/docs/guides/fiori#adding-odata-annotations) in `.cds` files - Support for [Fiori Draft](https://cap.cloud.sap/docs/guides/fiori#draft) - Support for [Value Helps](https://cap.cloud.sap/docs/guides/fiori#value-help) - Serving SAP Fiori apps locally - [The Vue.js app](bookshop/app/vue) imported from bookshop is served as well -
# All-in-one Monorepo diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index a8bfa7be..dd203f5c 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -152,69 +152,69 @@ describe('cds.ql → cqn', () => { expect(CQL`SELECT *,a,b from Foo`).to.eql(CQL`SELECT from Foo{*,a,b}`) //> .to.eql... FIXME: see skipped 'should handle * correctly' below expect(SELECT.from(Foo, ['a', 'b', '*'])) - .to.eql(SELECT.from(Foo).columns('a', 'b', '*')) - .to.eql(SELECT.from(Foo).columns(['a', 'b', '*'])) - .to.eql( - SELECT.from(Foo, (foo) => { - foo.a, foo.b, foo('*') - }) - ) - .to.eql({ - SELECT: { - from: { ref: ['Foo'] }, - columns: [{ ref: ['a'] }, { ref: ['b'] }, cdr ? '*' : { ref: ['*'] }], - }, + .to.eql(SELECT.from(Foo).columns('a', 'b', '*')) + .to.eql(SELECT.from(Foo).columns(['a', 'b', '*'])) + .to.eql( + SELECT.from(Foo, (foo) => { + foo.a, foo.b, foo('*') }) + ) + .to.eql({ + SELECT: { + from: { ref: ['Foo'] }, + columns: [{ ref: ['a'] }, { ref: ['b'] }, cdr ? '*' : { ref: ['*'] }], + }, }) + }) - test('from ( ..., => _.expand ( x=>{...}))', () => { - // SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } } - expect( - SELECT.from(Foo, (foo) => { - foo('*'), - foo.x, - foo.car('*'), - foo.boo((b) => { - b('*'), b.moo.zoo((x) => x.y.z) - }) - }) - ).to.eql({ - SELECT: { - from: { ref: ['Foo'] }, - columns: [ - cdr ? '*' : { ref: ['*'] }, - { ref: ['x'] }, - { ref: ['car'], expand: ['*'] }, - { - ref: ['boo'], - expand: ['*', { ref: ['moo', 'zoo'], expand: [{ ref: ['y', 'z'] }] }], - }, - ], - }, + test('from ( ..., => _.expand ( x=>{...}))', () => { + // SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } } + expect( + SELECT.from(Foo, (foo) => { + foo('*'), + foo.x, + foo.car('*'), + foo.boo((b) => { + b('*'), b.moo.zoo((x) => x.y.z) + }) }) + ).to.eql({ + SELECT: { + from: { ref: ['Foo'] }, + columns: [ + cdr ? '*' : { ref: ['*'] }, + { ref: ['x'] }, + { ref: ['car'], expand: ['*'] }, + { + ref: ['boo'], + expand: ['*', { ref: ['moo', 'zoo'], expand: [{ ref: ['y', 'z'] }] }], + }, + ], + }, }) + }) - test('from ( ..., => _.inline ( _=>{...}))', () => { - // SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } } - expect( - SELECT.from(Foo, (foo) => { - foo.bar('*'), - foo.bar('.*'), //> leading dot indicates inline - foo.boo((x) => x.moo.zoo), - foo.boo((_) => _.moo.zoo) //> underscore arg name indicates inline - }) - ).to.eql({ - SELECT: { - from: { ref: ['Foo'] }, - columns: [ - { ref: ['bar'], expand: ['*'] }, - { ref: ['bar'], inline: ['*'] }, - { ref: ['boo'], expand: [{ ref: ['moo', 'zoo'] }] }, - { ref: ['boo'], inline: [{ ref: ['moo', 'zoo'] }] }, - ], - }, + test('from ( ..., => _.inline ( _=>{...}))', () => { + // SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } } + expect( + SELECT.from(Foo, (foo) => { + foo.bar('*'), + foo.bar('.*'), //> leading dot indicates inline + foo.boo((x) => x.moo.zoo), + foo.boo((_) => _.moo.zoo) //> underscore arg name indicates inline }) + ).to.eql({ + SELECT: { + from: { ref: ['Foo'] }, + columns: [ + { ref: ['bar'], expand: ['*'] }, + { ref: ['bar'], inline: ['*'] }, + { ref: ['boo'], expand: [{ ref: ['moo', 'zoo'] }] }, + { ref: ['boo'], inline: [{ ref: ['moo', 'zoo'] }] }, + ], + }, }) + }) test('one / distinct ...', () => { expect(SELECT.distinct.from(Foo).SELECT) @@ -280,7 +280,7 @@ describe('cds.ql → cqn', () => { ).to.eql({ SELECT: { from: { ref: ['Foo'] }, - where: cdr + where: cds.version >= '5.3.0' ? [ // '(', //> this one is not required { ref: ['ID'] }, @@ -289,7 +289,7 @@ describe('cds.ql → cqn', () => { 'and', { ref: ['args'] }, 'in', - { val: args }, + { list: args.map(val => ({ val })) }, 'and', '(', //> this one is missing, and that's changing the logic -> that's a BUG { ref: ['x'] }, @@ -365,7 +365,7 @@ describe('cds.ql → cqn', () => { }, }) - expect( + if (!is_v2) expect( SELECT.from(Foo).where(`x=`, 1, `or y.z is null and (a>`, 2, `or b=`, 3, `)`) ).to.eql(CQL`SELECT from Foo where x=1 or y.z is null and (a>2 or b=3)`) diff --git a/test/custom-handlers.test.js b/test/custom-handlers.test.js index f8541a18..80b9ed71 100644 --- a/test/custom-handlers.test.js +++ b/test/custom-handlers.test.js @@ -6,13 +6,9 @@ else cds.User = cds.User.Privileged // hard core monkey patch for older cds rele describe('Custom Handlers', () => { it('should reject out-of-stock orders', async () => { - await expect( - Promise.all([ - POST('/browse/submitOrder', { book: 201, amount: 5 }), - POST('/browse/submitOrder', { book: 201, amount: 5 }), - POST('/browse/submitOrder', { book: 201, amount: 5 }), - ]) - ).to.be.rejectedWith(/409 - 5 exceeds stock for book #201/) + await POST('/browse/submitOrder', { book: 201, amount: 5 }) + await POST('/browse/submitOrder', { book: 201, amount: 5 }) + await expect(POST('/browse/submitOrder', { book: 201, amount: 5 })).to.be.rejectedWith(/409 - 5 exceeds stock for book #201/) const { data } = await GET`/admin/Books/201/stock/$value` expect(data).to.equal(2) }) diff --git a/test/hierarchical-data.test.js b/test/hierarchical-data.test.js index e411eff0..b374a320 100644 --- a/test/hierarchical-data.test.js +++ b/test/hierarchical-data.test.js @@ -1,11 +1,10 @@ const {expect} = require('../test') const cds = require('@sap/cds/lib') -// monkey patching older releases: -if (!cds.compile.cdl) cds.compile.cdl = cds.parse const { parse:cdr } = cds.ql -const model = cds.compile.cdl (` +// should become cds.compile(...) when cds5 is released +const model = cds.compile.to.csn (` entity Categories { key ID : Integer; name : String; diff --git a/test/index.js b/test/index.js index c44d3400..5a4fdd26 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,2 @@ - -const test = require('@sap/cds/lib/utils/tests').in(__dirname,'..') -module.exports = Object.assign(test,{run:test}) - -// REVISIT: With upcoming release of @sap/cds this should become: -// module.exports = require('@sap/cds/tests').in(__dirname,'..') +const cds = require('@sap/cds') +module.exports = cds.test.in(__dirname,'..') diff --git a/test/localized-data.test.js b/test/localized-data.test.js index bfa3411f..5ba9bd19 100644 --- a/test/localized-data.test.js +++ b/test/localized-data.test.js @@ -43,7 +43,7 @@ describe('Localized Data', () => { { title: 'Jane Eyre', author: 'Charlotte Brontë', currency: { name: 'Pfund' } }, { title: 'The Raven', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } }, { title: 'Eleonora', author: 'Edgar Allen Poe', currency: { name: 'US-Dollar' } }, - { title: 'Catweazle', author: 'Richard Carpenter', currency: { name: 'Euro' } }, + { title: 'Catweazle', author: 'Richard Carpenter', currency: { name: 'Yen' } }, ]) }) @@ -85,7 +85,7 @@ describe('Localized Data', () => { { title: 'Jane Eyre', currency: { name: 'British Pound' } }, { title: 'The Raven', currency: { name: 'US Dollar' } }, { title: 'Eleonora', currency: { name: 'US Dollar' } }, - { title: 'Catweazle', currency: { name: 'Euro' } }, + { title: 'Catweazle', currency: { name: 'Yen' } }, ]) }) }) diff --git a/test/messaging.test.js b/test/messaging.test.js index 42d20d38..3e2176b1 100644 --- a/test/messaging.test.js +++ b/test/messaging.test.js @@ -20,11 +20,11 @@ describe('Messaging', ()=>{ let N=0, received=[], M=0 it ('should add messaging event handlers', ()=>{ - srv.on('reviewed', (msg,next)=> { received.push(msg); return next() }) + srv.on('reviewed', (msg)=> received.push(msg)) }) it ('should add more messaging event handlers', ()=>{ - srv.on('reviewed', (_,next)=> { ++M; return next() }) + srv.on('reviewed', ()=> ++M) }) it ('should add review', async ()=>{