@vidyano-labs/virtual-service 0.4.0 → 0.4.1
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/index.js +46 -23
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
import { ServiceHooks, Service
|
|
1
|
+
import { DataType, ServiceHooks, Service } from '@vidyano/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Value conversion utilities for the virtual service.
|
|
5
|
+
* Wraps core DataType conversions to return JavaScript primitives instead of BigNumber.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Convert from service string to primitive
|
|
9
|
+
* fromServiceValue("100.50", "Decimal") // => 100.5 (number)
|
|
10
|
+
* fromServiceValue("True", "Boolean") // => true (boolean)
|
|
11
|
+
* fromServiceValue("15-01-2024 10:30:00", "DateTime") // => Date object
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Convert from primitive to service string
|
|
15
|
+
* toServiceValue(100.5, "Decimal") // => "100.5"
|
|
16
|
+
* toServiceValue(true, "Boolean") // => "True"
|
|
17
|
+
* toServiceValue(new Date(2024, 0, 15), "Date") // => "15-01-2024 00:00:00"
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Converts a service string value to a primitive JavaScript type.
|
|
21
|
+
* Unlike DataType.fromServiceString, this returns number instead of BigNumber
|
|
22
|
+
* for numeric types (Decimal, Double, Int64, etc.).
|
|
23
|
+
*/
|
|
24
|
+
function fromServiceValue(value, type) {
|
|
25
|
+
const result = DataType.fromServiceString(value, type);
|
|
26
|
+
// Check for BigNumber (has toNumber method) and convert to number primitive
|
|
27
|
+
if (result && typeof result.toNumber === "function")
|
|
28
|
+
return result.toNumber();
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a primitive JavaScript value to a service string.
|
|
33
|
+
*/
|
|
34
|
+
function toServiceValue(value, type) {
|
|
35
|
+
return DataType.toServiceString(value, type);
|
|
36
|
+
}
|
|
2
37
|
|
|
3
38
|
/**
|
|
4
39
|
* Business rule validator that supports built-in and custom rules
|
|
@@ -354,7 +389,7 @@ class VirtualQueryRegistry {
|
|
|
354
389
|
const rawValue = data[column.name];
|
|
355
390
|
return {
|
|
356
391
|
key: column.name,
|
|
357
|
-
value: rawValue == null ? null :
|
|
392
|
+
value: rawValue == null ? null : toServiceValue(rawValue, column.type),
|
|
358
393
|
objectId: data[column.name + "Id"],
|
|
359
394
|
typeHints: data[column.name + "$typeHints"]
|
|
360
395
|
};
|
|
@@ -495,10 +530,10 @@ function createVirtualQueryResultItem(dto, query) {
|
|
|
495
530
|
function createVirtualPersistentObjectAttribute(attr, persistentObject, service) {
|
|
496
531
|
const helpers = {
|
|
497
532
|
getValue() {
|
|
498
|
-
return
|
|
533
|
+
return fromServiceValue(attr.value, attr.type);
|
|
499
534
|
},
|
|
500
535
|
setValue(value) {
|
|
501
|
-
attr.value =
|
|
536
|
+
attr.value = toServiceValue(value, attr.type);
|
|
502
537
|
attr.isValueChanged = true;
|
|
503
538
|
},
|
|
504
539
|
setValidationError(error) {
|
|
@@ -537,7 +572,7 @@ function createVirtualPersistentObject(dto, service) {
|
|
|
537
572
|
let proxy;
|
|
538
573
|
// Cache wrapped queries to ensure same instance is returned
|
|
539
574
|
let wrappedQueries;
|
|
540
|
-
// Helper methods -
|
|
575
|
+
// Helper methods - delegate to attribute helpers where possible
|
|
541
576
|
const helpers = {
|
|
542
577
|
getAttribute(name) {
|
|
543
578
|
const attr = dto.attributes?.find(a => a.name === name);
|
|
@@ -546,17 +581,10 @@ function createVirtualPersistentObject(dto, service) {
|
|
|
546
581
|
return createVirtualPersistentObjectAttribute(attr, proxy, service);
|
|
547
582
|
},
|
|
548
583
|
getAttributeValue(name) {
|
|
549
|
-
|
|
550
|
-
if (!attr)
|
|
551
|
-
return undefined;
|
|
552
|
-
return VirtualService.fromServiceValue(attr.value, attr.type);
|
|
584
|
+
return proxy.getAttribute(name)?.getValue();
|
|
553
585
|
},
|
|
554
586
|
setAttributeValue(name, value) {
|
|
555
|
-
|
|
556
|
-
if (attr) {
|
|
557
|
-
attr.value = VirtualService.toServiceValue(value, attr.type);
|
|
558
|
-
attr.isValueChanged = true;
|
|
559
|
-
}
|
|
587
|
+
proxy.getAttribute(name)?.setValue(value);
|
|
560
588
|
},
|
|
561
589
|
setNotification(message, type, duration) {
|
|
562
590
|
dto.notification = message;
|
|
@@ -1174,16 +1202,15 @@ class VirtualPersistentObjectActions {
|
|
|
1174
1202
|
if (selectedItem == null) {
|
|
1175
1203
|
// Clear the reference
|
|
1176
1204
|
refAttr.objectId = null;
|
|
1177
|
-
referenceAttribute.
|
|
1205
|
+
referenceAttribute.setValue(null);
|
|
1178
1206
|
}
|
|
1179
1207
|
else {
|
|
1180
1208
|
// Set the reference to the selected item
|
|
1181
1209
|
refAttr.objectId = selectedItem.id;
|
|
1182
1210
|
// Get the display value from the item using displayAttribute
|
|
1183
1211
|
const displayAttribute = refAttr.displayAttribute;
|
|
1184
|
-
referenceAttribute.
|
|
1212
|
+
referenceAttribute.setValue(selectedItem.getValue(displayAttribute) || selectedItem.id);
|
|
1185
1213
|
}
|
|
1186
|
-
referenceAttribute.isValueChanged = true;
|
|
1187
1214
|
}
|
|
1188
1215
|
/**
|
|
1189
1216
|
* Called when the Delete action is executed on selected items in a Query
|
|
@@ -1681,17 +1708,13 @@ class VirtualService extends Service {
|
|
|
1681
1708
|
* for numeric types (Decimal, Double, Int64, etc.).
|
|
1682
1709
|
*/
|
|
1683
1710
|
static fromServiceValue(value, type) {
|
|
1684
|
-
|
|
1685
|
-
// Check for BigNumber (has toNumber method) and convert to number primitive
|
|
1686
|
-
if (result && typeof result.toNumber === "function")
|
|
1687
|
-
return result.toNumber();
|
|
1688
|
-
return result;
|
|
1711
|
+
return fromServiceValue(value, type);
|
|
1689
1712
|
}
|
|
1690
1713
|
/**
|
|
1691
1714
|
* Converts a primitive JavaScript value to a service string.
|
|
1692
1715
|
*/
|
|
1693
1716
|
static toServiceValue(value, type) {
|
|
1694
|
-
return
|
|
1717
|
+
return toServiceValue(value, type);
|
|
1695
1718
|
}
|
|
1696
1719
|
/**
|
|
1697
1720
|
* Gets a message by key with optional parameters.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vidyano-labs/virtual-service",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Virtual service implementation for testing Vidyano applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
"publishConfig": {
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
|
-
"gitHash": "
|
|
23
|
+
"gitHash": "23d8ce5cf6e9cef85601818b998c2732d60b7452"
|
|
24
24
|
}
|