@vidyano-labs/virtual-service 0.4.0 → 0.4.2
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 -24
- 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;
|
|
@@ -830,7 +858,6 @@ class VirtualServiceHooks extends ServiceHooks {
|
|
|
830
858
|
clientAttr.tab = configAttr.tab || "";
|
|
831
859
|
clientAttr.column = configAttr.column;
|
|
832
860
|
clientAttr.columnSpan = configAttr.columnSpan;
|
|
833
|
-
clientAttr.options = configAttr.options;
|
|
834
861
|
// Reference attribute properties - only set if explicitly configured
|
|
835
862
|
if (configAttr.lookup) {
|
|
836
863
|
const refAttr = clientAttr;
|
|
@@ -1174,16 +1201,15 @@ class VirtualPersistentObjectActions {
|
|
|
1174
1201
|
if (selectedItem == null) {
|
|
1175
1202
|
// Clear the reference
|
|
1176
1203
|
refAttr.objectId = null;
|
|
1177
|
-
referenceAttribute.
|
|
1204
|
+
referenceAttribute.setValue(null);
|
|
1178
1205
|
}
|
|
1179
1206
|
else {
|
|
1180
1207
|
// Set the reference to the selected item
|
|
1181
1208
|
refAttr.objectId = selectedItem.id;
|
|
1182
1209
|
// Get the display value from the item using displayAttribute
|
|
1183
1210
|
const displayAttribute = refAttr.displayAttribute;
|
|
1184
|
-
referenceAttribute.
|
|
1211
|
+
referenceAttribute.setValue(selectedItem.getValue(displayAttribute) || selectedItem.id);
|
|
1185
1212
|
}
|
|
1186
|
-
referenceAttribute.isValueChanged = true;
|
|
1187
1213
|
}
|
|
1188
1214
|
/**
|
|
1189
1215
|
* Called when the Delete action is executed on selected items in a Query
|
|
@@ -1681,17 +1707,13 @@ class VirtualService extends Service {
|
|
|
1681
1707
|
* for numeric types (Decimal, Double, Int64, etc.).
|
|
1682
1708
|
*/
|
|
1683
1709
|
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;
|
|
1710
|
+
return fromServiceValue(value, type);
|
|
1689
1711
|
}
|
|
1690
1712
|
/**
|
|
1691
1713
|
* Converts a primitive JavaScript value to a service string.
|
|
1692
1714
|
*/
|
|
1693
1715
|
static toServiceValue(value, type) {
|
|
1694
|
-
return
|
|
1716
|
+
return toServiceValue(value, type);
|
|
1695
1717
|
}
|
|
1696
1718
|
/**
|
|
1697
1719
|
* 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.2",
|
|
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": "79e3626e489dad1001f311fcec3fb18e06b0a85a"
|
|
24
24
|
}
|