Npm log levels used for the SAP Cloud SDK logger.
Denotes the OData version.
Default logger for the SAP Cloud SDK for unhandled exceptions.
Format for logging in Kibana.
Format for local logging.
Adds a key value pair to the given objects and returns a shallow copy. If the key is already present it will be overwritten.
key to be added
value to be added
object the key value pair is added to.
the object with the key value pair added
Adds the value to the object if it is neither null nor undefined. Note that this is different to JS idiomatic checks for truthy/falsy values, i.e. an empty string will result in key/value pairs beeing added.
The key to associate with the given value.
The value to associate with the given key.
A copy of the input object with the new key-value pair if the value is neither null nor undefined.
The object on which to create the association.
Same as pipe but for asynchronous functions: asynvPipe(finc1,func2,...funcN)(start) executes all functions in sequence awaiting the result and piping the response through in other words await funcN(... await func2(await func1(start))...)
a list of asynchronous functions to be executed in sequence
the reponse of the last function in the list.
start value for the first function in the list
Convert a string to camelCase. This format used e. g. for properties on entity class instances.
The string to be transformed.
The transformed string.
Returns the OData version in capital letters so V2 or V4.
OData version in lower case: 'v2' or 'v4'
'V2' or 'V4'
Strings in the tagged template. In the example above that would be ['Code with ', ' and more code;'].
Arguments in the tagged template. In the example above that would be the resolved value for arguments
;
A string formatted as code block.
Create a logger for the given message context, if available.
Usage:
To create a logger in your module, it is recommended to pass a module identifier that will be logged as messageContext
for all messages from this logger:
const logger = createLogger('my-module');
. Not setting any module identifier will retrieve the default logger.
Use this logger throughout your module. If the module is spread over multiple files, you can retrieve the logger instance by calling the createLogger
function with the respective module identifier.
There will always be only one instance of a logger per module identifier.
You can pass any custom data that you want to be logged in addition by passing an object instead. You can change the default logging level (INFO
) using the level
key in the object.
In those cases, provide the messageContext
as a key in the object:
const logger = createLogger({
messageContext: 'my-module',
myCustomKey: 'my-custom-data',
level: 'debug'
});
You will find these information under the _custom_fields_ key in your Cloud Foundry logs.
To retrieve a logger after its creation use getLogger. If you want to change the log level of a logger use setLogLevel.
Either a key for the message context of all messages produced by the logger or an object with additional keys to set in the message.
A newly created or an already existing logger for the given context.
Disable logging of exceptions. Enabled by default.
Enable logging of exceptions. Enabled by default.
Encode a string to a base64 encoded string.
String to encode.
Base64 encoded string.
hidden
hidden
hidden
Error message.
Original error, causing the new error.
A new error with the given cause.
Filter an array by removing duplicates and keeping the left most occurence. By default this compares by identity.
Array to remove duplicates from.
Optional comparator function, indicating whether two items are equal and therefore handled as duplicates. Defaults to identity.
A filtered array containing no duplicates.
Filter an array by removing duplicates and keeping the right most occurence. By default this compares by identity.
Array to remove duplicates from.
Optional comparator function, indicating whether two items are equal and therefore handled as duplicates. Defaults to identity.
A filtered array containing no duplicates.
Get the first item from an array. Returns undefined if the array is empty.
Array to get the first item of
Fist item of the array or undefined if the array was empty
Flatten a two dimensional array into a one dimensional array
The array to be flattened.
A one dimensional array.
Flattens a array: [1,[2,[3,4]],5] will become [1,2,3,4,5]. Non primitive values are copied by reference.
Array to be flattened
The flattened array.
Get logger for a given message context, if avilable.
A key for the message context of all messages produced by the logger
The logger for the given messageContext if it was created before
Identity function
Any object
the given argument without doing something
Type guard to check whether an error is of type ErrorWithCause.
An error.
Whether the given error is of type ErrorWithCause.
Checks whether a value is either null
or undefined
.
Value to check
true for null or undefined, false otherwise.
Get the last item from an array. Returns undefined if the array is empty.
Array to get the last item of
Last item of the array or undefined if the array was empty
Create an object by merging the right
object into a shallow copy of the left
object ignoring casing, but keeping the right casing. Keys present both objects will be present in the merged object.
Object to merge.
Object to merge. The casing of the keys of this object takes precedence.
right
object are replaced. Note that the casing used by right
will be used.Create an object by merging the right
object into a shallow copy of the left
object ignoring casing, but keeping the right
casing. Only keys present in the left
object will be present in the merged object.
Object to merge into. They keys of this object will be present in the returned object.
Object to merge. Only keys in left
will be considered for merging.
left
object, where entries present in the right
object are replaced. Note that the casing used by right
will be used.Merges the two objects, if second object is neither null nor undefined. If a key exists on a and b the value from b is taken
The object to merge into.
The object which to merge into a.
A copy of the merge(a, b) or a if b is undefined or null.
Mute all logger output created by the SAP Cloud SDK Logger. This also applies to future loggers created. Useful for tests.
Split an array into two based on a condition.
Array to partition
Function to determine to where to put each item.
A two dimensional array containting two arrays, where the first one includes all items where the given condition was met and the second one includes all items where it was not met.
Convert a string to pascal case. This format is used e. g. for types.
The string to be transformed.
The transformed string.
Create a shallow copy of the given object, that contains the given keys. Non existing keys in the source object are ignored.
properties to be selected
object from which the values are taken
an object with the selected keys and corresponding values.
Create a shallow copy of the given object, that contains the given keys, independent of casing. Non existing keys in the source object are ignored.
Object to pick the given key from.
Keys of the pair to be picked.
Create a shallow copy of the given object, that contains all entries with non-nullish values.
An object to pick from.
Returns the value of an object based on the given key, independent of casing.
Object to be searched for the given key.
Key of the value to pick.
The value of for the given key or undefined if not available.
Checks if a chain of properties exists on the given object.
The object to be checked.
Chained properties.
True if the property chain leads to a truthy value, false otherwise.
Read a JSON file from the file system.
The path to the JSON file.
An object parsed from the JSON file.
Takes an object and returns a new object whose keys are renamed according to the provided key mapping. Any keys in the input object not present in the key mapping will be present in the output object as-is. If a key in the key mapping is not present in the input object, the output object will contain the key with value "undefined".
An object mapping keys of the input object to keys of the output object.
The input object.
An object with renamed keys.
Change the global log level of the container which will set default level for all active loggers.
E. g., to set the global log level call setGlobalLogLevel('debug')
.
Change the log level of a logger based on its message context.
E. g., to set the log level for the destination accessor module of the SDK to debug, simply call setLogLevel('debug', 'destination-acessor')
.
level to set the logger to. Use an empty string '' as level to unset context level.
Message context of the logger to change the log level for or the logger itself
Split the given array in chunks
Array to be split into chunks.
Size of the chunks
Two dimensional array with arrays of length chunkSize. The last subarray could be shorter.
Convert a string to a human readable format, e.g. it transforms to_BusinessPartner
to To Business Partner
.
The string to be transformed.
The transformed string.
Create an object based on the given key and value if neither key nor value are nullish.
Name of the header.
Value of the header.
Remove whitespace from the left side of a string.
String to trim.
String without outer whitespace.
Remove whitespace from the left side of a string.
String to trim.
String without whitespace on the left side.
Remove whitespace from the right side of a string.
String to trim.
String without whitespace on the right side.
Remove all duplicates from array
Array that might contain duplicates
Array of unique items
Unmute all logger output created by the SAP Cloud SDK Logger. This also applies to future loggers created. Useful for tests.
Convert a string to the uppercase snake case. This format is used e. g. for static properties on entity classes.
The string to be transformed.
The input string in the case used by static methods on entity-classes.
We want to provide methods which accept a variable single number of elements and arrays. The overloaded signature to achieve this is: function doSomething(array: T[]) function doSomething(...varArgs: T[]) functiondoSomething(first: undefined | T | T[], ...rest: T[]) { //implementation } This wrapper methods makes it easy build an array from the input.
Either an array, the first element of the var args or undefined if no argument was given.
Second to last element if var args were used, empty array if the frist argument is an array.
Array from the input or empty array if no input was given.
Merge two arrays by alternately adding inserting values from both arrays, starting from the left.
For example: zip([1, 2], [3, 4, 5, 6])
=> [1, 3, 2, 4, 5, 6]
Array to start alternately merging from.
Second array to merge.
Zipped array.
@sap-cloud-sdk/util
Package that contains general utility functions that we reuse multiple times in the SDK. While primarily designed for internal usage, they might also be beneficial for consumers of the SDK.
Installation
Usage
The util package collects useful tools that help build your SAP Cloud Platform application. For example, the following code snippet changes the log level of the destination accessor of the SDK.
Documentation
Getting started guide API documentation
Helpful Links