esi-cap 1.7.33 → 1.7.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/index.md ADDED
@@ -0,0 +1,73 @@
1
+ # esi-cap Utilities API Reference
2
+
3
+ > **Module:** `esi-cap` Package
4
+ > **Purpose:** `esi-cap` is a specialized API package designed for **Enterprise System Integration** within the [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap/docs/) framework. It streamlines communication with remote systems and provides native support for service associations, requiring minimal configuration to achieve out-of-the-box connectivity.
5
+ > **Package Structure:** The package is organized into two primary modules:
6
+ > **`esi` Module**: Contains the core integration logic and foundational functions for system communication.
7
+ > **`utils` Module**: Provides a suite of generic utility functions to support common development tasks.
8
+
9
+ ---
10
+
11
+ ## Table of Contents
12
+
13
+ - [Exports](#exports)
14
+ - [Module: `esi`](#module-esi)
15
+ - [Module: `utils`](#module-utils)
16
+ - [Quick Usage Examples](#quick-usage-examples)
17
+
18
+ ---
19
+
20
+ ## Exports
21
+
22
+ ```js
23
+ module.exports = { esi, utils };
24
+ ```
25
+
26
+ ---
27
+
28
+ ## Module: `esi`
29
+
30
+ Contains the core integration logic and foundational functions for system communication. Its core capabilities are outlined below:
31
+
32
+ | Feature | Module Name | Description |
33
+ | :--- | :--- | :--- |
34
+ | **Remote Communication** | `connect` | Streamlined protocols for connecting to external APIs. Simplifies connectivity with minimal configuration. It supports API of soap, odata v4/v2, rest, iflow-https. |
35
+ | **Service Implementation** | `impl` | Native support for remote service associations. Reduces boilerplate code for complex data models. |
36
+ | **Enriched Logging** | `log` | Pre-configured patterns for SAP environment logging. Accelerates development using CAP best practices. |
37
+ | **Core Functions** | `service`, `query` | Foundational functions for system-to-system messaging. Ensures consistent data handling across the enterprise. |
38
+
39
+
40
+ ---
41
+
42
+ ## Module: `utils`
43
+
44
+ Provides a suite of generic utility functions to support common development tasks. Refer to the [utils Documentation](./lib/utils/index.md) for more details.
45
+
46
+
47
+ ---
48
+
49
+ ## Quick Usage Examples
50
+
51
+ ```js
52
+ const { cds } = require('@sap/cds');
53
+ const { esi, utils } = require('esi-cap');
54
+
55
+ // impl usage
56
+ const srvImpl = cds.service.impl(esi.impl.RemoteService);
57
+
58
+ // connect usage
59
+ const srv = esi.connect.to('<ServiceName>');
60
+ srv.run(SELECT.from('<EntityName').where('<Where Clause').columns('<Columns list'));
61
+
62
+ // log usage
63
+ const logger = esi.log('<LoggerName>');
64
+ const data = { a: 1, b: "Hello" };
65
+ logger.warn(esi.service.events.PreOn, req, "data", data); // [2026-01-01T12:32:20.197Z] [WARN] [<LoggerName>] [PreOn:READ:<Name of Service>.<Name of Entity>] - data | { a: 1, b: "Hello" }
66
+
67
+ // utils usage
68
+ const valid = await utils.date.isValid("2026-04-20");
69
+ const items = [{ id: 1, name: "A" }, { id: 2, name: "B" }];
70
+ const grouped = utils.array.toGroupByPropertyName(items, "name");
71
+ const merged = utils.json.merge({ a: 1 }, { b: 2 }); // { a: 1, b: 2 }
72
+
73
+ ```
@@ -1,7 +1,7 @@
1
1
  # esi-cap Utilities API Reference
2
2
 
3
- > **Module:** `src/lib/utils/index.js`
4
- > **Purpose:** Core utility belt for the esi-cap framework — date validation, XML parsing, JSON manipulation, array operations, and UUID generation/parsing.
3
+ > **Module:** `utils`
4
+ > **Purpose:** Core utility belt — date validation, XML parsing, JSON manipulation, array operations, and UUID generation/parsing.
5
5
 
6
6
  ---
7
7
 
@@ -9,11 +9,11 @@
9
9
 
10
10
  - [Dependencies](#dependencies)
11
11
  - [Exports](#exports)
12
- - [Namespace: `date`](#namespace-date)
12
+ - [Class: `date`](#class-date)
13
13
  - [date.isValid(sDate)](#dateisvalidsdate)
14
- - [Namespace: `xml`](#namespace-xml)
14
+ - [Class: `xml`](#class-xml)
15
15
  - [xml.isValid(oXML)](#xmlisvalidoxml)
16
- - [Namespace: `json`](#namespace-json)
16
+ - [Class: `json`](#class-json)
17
17
  - [json.isValid(oJson)](#jsonisvalidojson)
18
18
  - [json.copy(oJson)](#jsoncopyojson)
19
19
  - [json.replace(oJson, sOldValue, sNewValue, oEvaluate?)](#jsonreplaceojson-soldvalue-snewvalue-oevaluate)
@@ -25,7 +25,7 @@
25
25
  - [json.merge(oJson1, oJson2)](#jsonmergeojson1-ojson2)
26
26
  - [json.flat(oJson, sFlattenedProperty)](#jsonflatojson-sflattenedproperty)
27
27
  - [json.stripUndefined(oSourceJson)](#jsonstripundefinedosourcejson)
28
- - [Namespace: `array`](#namespace-array)
28
+ - [Class: `array`](#class-array)
29
29
  - [array.add(oArray, oItem)](#arrayaddoarray-oitem)
30
30
  - [array.topN(oSortedArray, iTop)](#arraytopnosortedarray-itop)
31
31
  - [array.flat(oArray, sFlattenedProperty)](#arrayflatoarray-sflattenedproperty)
@@ -57,21 +57,20 @@
57
57
  | `xml2js` | XML string parsing and validation |
58
58
  | `uuid` | UUID format validation |
59
59
  | `lodash` | Deep merge, orderBy, uniqWith, and isEqual |
60
- | `../_interface` | Internal logger and `_LOG` constant |
61
60
 
62
61
  ---
63
62
 
64
63
  ## Exports
65
64
 
66
65
  ```js
67
- module.exports = { date, xml, json, array, UUID, _LOG };
66
+ module.exports = { date, xml, json, array, UUID };
68
67
  ```
69
68
 
70
69
  ---
71
70
 
72
- ## Namespace: `date`
71
+ ## Class: `date`
73
72
 
74
- Date-related validation helpers.
73
+ Date-related validation helpers. All methods are `static`.
75
74
 
76
75
  ### `date.isValid(sDate)`
77
76
 
@@ -89,9 +88,9 @@ await date.isValid("not-a-date"); // false
89
88
 
90
89
  ---
91
90
 
92
- ## Namespace: `xml`
91
+ ## Class: `xml`
93
92
 
94
- XML parsing and validation helpers.
93
+ XML parsing and validation helpers. All methods are `static`.
95
94
 
96
95
  ### `xml.isValid(oXML)`
97
96
 
@@ -104,14 +103,14 @@ XML parsing and validation helpers.
104
103
 
105
104
  ```js
106
105
  await xml.isValid("<root><item>val</item></root>"); // true
107
- await xml.isValid("not xml"); // false
106
+ await xml.isValid("not xml"); // false
108
107
  ```
109
108
 
110
109
  ---
111
110
 
112
- ## Namespace: `json`
111
+ ## Class: `json`
113
112
 
114
- Comprehensive JSON/object manipulation utilities.
113
+ Comprehensive JSON/object manipulation utilities. All methods are `static`.
115
114
 
116
115
  ### `json.isValid(oJson)`
117
116
 
@@ -243,9 +242,9 @@ Removes properties where the value is `undefined`, `null`, or an empty string.
243
242
 
244
243
  ---
245
244
 
246
- ## Namespace: `array`
245
+ ## Class: `array`
247
246
 
248
- Array operations with automatic fallback to `json` namespace for single-object inputs.
247
+ Array operations with automatic fallback to the `json` class for single-object inputs. All methods are `static`.
249
248
 
250
249
  ### `array.add(oArray, oItem)`
251
250
 
@@ -399,7 +398,7 @@ array.toGroupByPropertyList(data, ["region", "details.category"]);
399
398
 
400
399
  ## Class: `UUID`
401
400
 
402
- Singleton class for deterministic UUID generation and parsing based on a fixed field configuration. Encodes/decodes structured business data (CompanyCode, PersonWorkAgreementExternalID, TimeSheetRecord) into RFC-4122-compliant UUIDs.
401
+ Singleton class for deterministic UUID generation and parsing based on a fixed field configuration. Encodes/decodes structured business data into RFC-4122-compliant UUIDs.
403
402
 
404
403
  ### Constructor
405
404
 
@@ -409,14 +408,6 @@ const uuidHelper = new UUID();
409
408
 
410
409
  Creates a singleton instance. Subsequent `new UUID()` calls return the same instance.
411
410
 
412
- **Internal field configuration:**
413
-
414
- | Field | Order | Format (Regex) | Description |
415
- |---|---|---|---|
416
- | `CompanyCode` | 1 | `/^[A-Za-z]{2}\d{2}$/` | 2 letters + 2 digits |
417
- | `PersonWorkAgreementExternalID` | 2 | `/^[Ii]\d{7}$\|^\d{1,9}$/` | I-number or numeric ID |
418
- | `TimeSheetRecord` | 3 | `/^\d{12}$/` | 12-digit record number |
419
-
420
411
  ---
421
412
 
422
413
  ### `converse(oJsonData)`
@@ -425,16 +416,16 @@ Encodes structured JSON data into a deterministic UUID.
425
416
 
426
417
  | Parameter | Type | Description |
427
418
  |------------|----------|-------------------------------------------|
428
- | `oJsonData` | `object` | Object with `CompanyCode`, `PersonWorkAgreementExternalID`, `TimeSheetRecord` |
419
+ | `oJsonData` | `object` | Object |
429
420
  | **Returns** | `string` | A valid UUID string |
430
421
  | **Throws** | `Error` | If any field has an invalid format or the generated UUID fails validation |
431
422
 
432
423
  ```js
433
424
  const uid = new UUID();
434
425
  uid.converse({
435
- CompanyCode: "AB12",
436
- PersonWorkAgreementExternalID: "I1234567",
437
- TimeSheetRecord: "000000012345"
426
+ ABC: "AB12",
427
+ MNO: "I1234567",
428
+ XYZ: "000000012345"
438
429
  });
439
430
  // Returns a valid UUID string e.g., "c0656612-2e12-4345-8670-000000012345"
440
431
  ```
@@ -448,12 +439,12 @@ Decodes a previously generated UUID back into its original structured data.
448
439
  | Parameter | Type | Description |
449
440
  |-----------|----------|------------------------------------|
450
441
  | `sUUID` | `string` | A UUID previously created by `converse` |
451
- | **Returns** | `object` | `{ CompanyCode, PersonWorkAgreementExternalID, TimeSheetRecord }` or `{}` if invalid |
442
+ | **Returns** | `object` | `{ ABC, MNO, XYZ }` or `{}` if invalid |
452
443
 
453
444
  ```js
454
445
  const uid = new UUID();
455
446
  uid.inverse("c0656612-2e12-4345-8670-000000012345");
456
- // { CompanyCode: "AB12", PersonWorkAgreementExternalID: "I1234567", TimeSheetRecord: "000000012345" }
447
+ // { ABC: "AB12", MNO: "I1234567", XYZ: "000000012345" }
457
448
  ```
458
449
 
459
450
  ---
@@ -461,7 +452,7 @@ uid.inverse("c0656612-2e12-4345-8670-000000012345");
461
452
  ## Quick Usage Examples
462
453
 
463
454
  ```js
464
- const { date, xml, json, array, UUID } = require('./src/lib/utils');
455
+ const { date, xml, json, array, UUID } = require('esi-cap').utils;
465
456
 
466
457
  // Validate & transform
467
458
  const valid = await date.isValid("2026-04-20");
@@ -478,6 +469,6 @@ const merged = json.merge({ a: 1 }, { b: 2 }); // { a: 1, b:
478
469
 
479
470
  // UUID round-trip
480
471
  const uid = new UUID();
481
- const uuidStr = uid.converse({ CompanyCode: "AB12", PersonWorkAgreementExternalID: "I1234567", TimeSheetRecord: "000000012345" });
472
+ const uuidStr = uid.converse({ ABC: "AB12", MNO: "I1234567", XYZ: "000000012345" });
482
473
  const original = uid.inverse(uuidStr);
483
474
  ```