Node.js Code Samples (SAP HANA): Unterschied zwischen den Versionen

Aus MattWiki
(Die Seite wurde neu angelegt: „Dieser Artikel enthält SAP HANA Spezifsche Codesamples zur Ausführung mit Node.js in der XS Advanced Umgebung. Grundlagen zur JavaScript Sprache selbst sieh…“)
 
Keine Bearbeitungszusammenfassung
 
(22 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
Dieser Artikel enthält SAP HANA Spezifsche Codesamples zur Ausführung mit Node.js in der XS Advanced Umgebung.
This entry contains SAP HANA specific server-side JavaScript listings for Node.js runtime within XS Advanced environment.


Grundlagen zur JavaScript Sprache selbst siehe [[JavaScript Basics]]
For basics knowledge on JavaScript language itself see [[JavaScript Linkliste]]


== Language Basics for XSJS Runtime ==
== Language Basics on Node.js Runtime ==


String: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-strings.xsjs
https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/JavaScriptBasics.js


Datum: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-dates.xsjs
Content:  


Arrays: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-arrays.xsjs
/dates - Date processing
/array - Array processing
/json - JSON JavaScript Object Notation processing
/objects - JavaScript Objects
/strings - String processing
/classes - JavaScript Classes
/promises - Promises
/constants - Constants
/blockScoped - Block-Scoped Variables and Functions
/parameterDefaults - Parameter Defaults
/parameterMultiple - Handling unknown number of input parameters easily
/unicode - Unicode Strings and Literals
/numFormat - International Number Formatting
/currFormat - International Currency Formatting
/dateFormat - International Date/Time Formatting


JSON-Output: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-json.xsjs
== Text Bundles ==


Objects: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-objects.xsjs
'''Lessons Learned'''


Classes: https://github.com/mattxdev/openSAPHANA/blob/master/xsjs/lib/xsjs/JavaScriptBasics/my-classes.xsjs
* Use TextBundle module '''@sap/textbundle"''';
* Get locale from Client Browser Headers
* Store language specific text files in _i18n subfolder
* Create instance bundle of type TextBundle
* Get text with getText Method of bundle instance


== Language Basics for Node.js Runtime ==
https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/textBundle.js


== Open Source Modules for Node.js ==


== Text Bundles ==
How to utilize open source Node.js modules for:


* '''Create Excel:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/excel.js
* '''Create and parse XML:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/xml.js
* '''Create ZIP:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/zip.js


== Object Oriented JavaScript ==
== Object Oriented JavaScript ==
'''''Types of Class Implementations'''''
* '''Constructor and this-keyword:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/ooTutorial1.js
* '''Static methods:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/ooTutorial2.js
* '''Instance methods:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/ooTutorial3.js
* '''Inheritance and extending methods:''' https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/ooTutorial4.js
'''''Instanciating and Utilization of Classes'''''
https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/oo.js


== WebSockets ==
== WebSockets ==
By default Webaccess is initiiated from the browser / client side by sending a request to the server in order to receive a result.
In use cases where one would like to update the data on the client side when something changed on server side the resulting periodical polling would not be efficient.
With Web Sockets the server can initiate the communication with one or even multiple clients at a time. This enables BI and Dashboard applications where the server can send new data to the client as soon as is has changed in the database.
'''Example: Chat application'''
https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/chatServer.js
== Exits for OData V4 Services ==
Data models for OData V4 Services can be based on:
* CDS views
* HANA SQL views (as the example below)
* Calculation Views
* Synonyms for Calculation Views
They can be extended on the service level like this:
using PURCHASE_ORDER_ITEM_VIEW as ItemsView from '../db/data-model';
service CatalogService {
...
extend ItemsView with {
  PARTNERS: association to BuyerView on PARTNERS.PARTNERID = PARTNER_ID;
}
entity POItemsView @(
    title: '{i18n>poService}',
    Capabilities: {
      InsertRestrictions: {Insertable: false},
      UpdateRestrictions: {Updatable: false},
      DeleteRestrictions: {Deletable: false}
    }
  ) as projection on ItemsView;
...
}
Exits for OData V4 Services in Node.js are possible for:
* Before
* On
* After
for operations:
* Create
* Read
* Update
* Delete
CDS definition in ''/srv/server.js'' defines with <code>.with(require("./lib/handlers"))</code> where to look for exit handlers.
Listing: https://github.com/mattxdev/opensap-hana7/blob/master/srv/lib/handlers/index.js
[[Category:JavaScript]]
[[Category:SAP]]
[[Category:HANA]]

Aktuelle Version vom 27. März 2022, 19:03 Uhr

This entry contains SAP HANA specific server-side JavaScript listings for Node.js runtime within XS Advanced environment.

For basics knowledge on JavaScript language itself see JavaScript Linkliste

Language Basics on Node.js Runtime

https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/JavaScriptBasics.js

Content:

/dates - Date processing
/array - Array processing
/json - JSON JavaScript Object Notation processing
/objects - JavaScript Objects
/strings - String processing
/classes - JavaScript Classes
/promises - Promises
/constants - Constants
/blockScoped - Block-Scoped Variables and Functions
/parameterDefaults - Parameter Defaults
/parameterMultiple - Handling unknown number of input parameters easily
/unicode - Unicode Strings and Literals
/numFormat - International Number Formatting
/currFormat - International Currency Formatting
/dateFormat - International Date/Time Formatting

Text Bundles

Lessons Learned

  • Use TextBundle module @sap/textbundle";
  • Get locale from Client Browser Headers
  • Store language specific text files in _i18n subfolder
  • Create instance bundle of type TextBundle
  • Get text with getText Method of bundle instance

https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/textBundle.js

Open Source Modules for Node.js

How to utilize open source Node.js modules for:

Object Oriented JavaScript

Types of Class Implementations

Instanciating and Utilization of Classes

https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/oo.js

WebSockets

By default Webaccess is initiiated from the browser / client side by sending a request to the server in order to receive a result.

In use cases where one would like to update the data on the client side when something changed on server side the resulting periodical polling would not be efficient.

With Web Sockets the server can initiate the communication with one or even multiple clients at a time. This enables BI and Dashboard applications where the server can send new data to the client as soon as is has changed in the database.

Example: Chat application

https://github.com/mattxdev/opensap-hana7/blob/master/srv/router/routes/chatServer.js

Exits for OData V4 Services

Data models for OData V4 Services can be based on:

  • CDS views
  • HANA SQL views (as the example below)
  • Calculation Views
  • Synonyms for Calculation Views

They can be extended on the service level like this:

using PURCHASE_ORDER_ITEM_VIEW as ItemsView from '../db/data-model';

service CatalogService {

...

extend ItemsView with {
  PARTNERS: association to BuyerView on PARTNERS.PARTNERID = PARTNER_ID;
}

entity POItemsView @(
    title: '{i18n>poService}',
    Capabilities: {
      InsertRestrictions: {Insertable: false},
      UpdateRestrictions: {Updatable: false},
      DeleteRestrictions: {Deletable: false}
    }
  ) as projection on ItemsView;

...
}

Exits for OData V4 Services in Node.js are possible for:

  • Before
  • On
  • After

for operations:

  • Create
  • Read
  • Update
  • Delete

CDS definition in /srv/server.js defines with .with(require("./lib/handlers")) where to look for exit handlers.

Listing: https://github.com/mattxdev/opensap-hana7/blob/master/srv/lib/handlers/index.js