@vidyano-labs/virtual-service 0.4.3 → 0.5.0
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/README.md +5 -5
- package/index.d.ts +6 -6
- package/index.js +37 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -144,7 +144,7 @@ Common attribute types supported by the virtual service:
|
|
|
144
144
|
| `Date` | Dates only | `"2026-01-23"` |
|
|
145
145
|
| `Byte` | Small integers (0-255) | `128` |
|
|
146
146
|
|
|
147
|
-
> **Note:**
|
|
147
|
+
> **Note:** Use native JavaScript types (boolean, number, Date, etc.) when setting attribute values. The `getValue<T>()` and `setValue<T>()` methods work directly with these types and support generics for type safety (e.g., `getValue<number>()`).
|
|
148
148
|
|
|
149
149
|
### Attribute Configuration
|
|
150
150
|
|
|
@@ -1142,8 +1142,8 @@ async onSave(obj: VirtualPersistentObject): Promise<VirtualPersistentObject> {
|
|
|
1142
1142
|
| Method | Description |
|
|
1143
1143
|
|--------|-------------|
|
|
1144
1144
|
| `getAttribute(name)` | Get attribute by name |
|
|
1145
|
-
| `getAttributeValue(name)` | Get
|
|
1146
|
-
| `setAttributeValue(name, value)` | Set attribute value
|
|
1145
|
+
| `getAttributeValue<T>(name)` | Get attribute value |
|
|
1146
|
+
| `setAttributeValue<T>(name, value)` | Set attribute value |
|
|
1147
1147
|
| `setValidationError(name, error)` | Set validation error (pass `null`/empty to clear) |
|
|
1148
1148
|
| `setNotification(msg, type, duration?)` | Set notification |
|
|
1149
1149
|
| `service` | Reference to the VirtualService instance |
|
|
@@ -1152,8 +1152,8 @@ async onSave(obj: VirtualPersistentObject): Promise<VirtualPersistentObject> {
|
|
|
1152
1152
|
|
|
1153
1153
|
| Method | Description |
|
|
1154
1154
|
|--------|-------------|
|
|
1155
|
-
| `getValue()` | Get
|
|
1156
|
-
| `setValue(value)` | Set value
|
|
1155
|
+
| `getValue<T>()` | Get value |
|
|
1156
|
+
| `setValue<T>(value)` | Set value |
|
|
1157
1157
|
| `setValidationError(error)` | Set validation error (pass `null`/empty to clear) |
|
|
1158
1158
|
| `persistentObject` | Reference to the parent VirtualPersistentObject |
|
|
1159
1159
|
| `service` | Reference to the VirtualService instance |
|
package/index.d.ts
CHANGED
|
@@ -93,13 +93,13 @@ type VirtualPersistentObjectAttributeWithReference = Dto.PersistentObjectAttribu
|
|
|
93
93
|
*/
|
|
94
94
|
type VirtualPersistentObjectAttributeHelpers = {
|
|
95
95
|
/**
|
|
96
|
-
* Gets the
|
|
96
|
+
* Gets the value of this attribute
|
|
97
97
|
*/
|
|
98
|
-
getValue():
|
|
98
|
+
getValue<T = any>(): T;
|
|
99
99
|
/**
|
|
100
|
-
* Sets the value of this attribute
|
|
100
|
+
* Sets the value of this attribute
|
|
101
101
|
*/
|
|
102
|
-
setValue(value:
|
|
102
|
+
setValue<T = any>(value: T): void;
|
|
103
103
|
/**
|
|
104
104
|
* Sets a validation error on this attribute. Pass null/empty to clear.
|
|
105
105
|
*/
|
|
@@ -125,11 +125,11 @@ type VirtualPersistentObject = Omit<Dto.PersistentObjectDto, "queries"> & {
|
|
|
125
125
|
/**
|
|
126
126
|
* Gets the value of an attribute by name
|
|
127
127
|
*/
|
|
128
|
-
getAttributeValue(name: string):
|
|
128
|
+
getAttributeValue<T = any>(name: string): T;
|
|
129
129
|
/**
|
|
130
130
|
* Sets the value of an attribute by name
|
|
131
131
|
*/
|
|
132
|
-
setAttributeValue(name: string, value:
|
|
132
|
+
setAttributeValue<T = any>(name: string, value: T): void;
|
|
133
133
|
/**
|
|
134
134
|
* Sets a notification message on the persistent object
|
|
135
135
|
*/
|
package/index.js
CHANGED
|
@@ -471,8 +471,9 @@ function createVirtualQuery(dto, config, service) {
|
|
|
471
471
|
return proxy;
|
|
472
472
|
}
|
|
473
473
|
/**
|
|
474
|
-
* Unwraps a VirtualQuery to get the underlying DTO
|
|
475
|
-
*
|
|
474
|
+
* Unwraps a VirtualQuery to get the underlying DTO.
|
|
475
|
+
* Also accepts raw DTOs for recursive handling.
|
|
476
|
+
* @param wrapped - The VirtualQuery or QueryDto to unwrap
|
|
476
477
|
* @returns The underlying QueryDto
|
|
477
478
|
*/
|
|
478
479
|
function unwrapVirtualQuery(wrapped) {
|
|
@@ -521,13 +522,14 @@ function createVirtualQueryResultItem(dto, query) {
|
|
|
521
522
|
* @returns A VirtualPersistentObjectAttribute that combines DTO properties with helper methods
|
|
522
523
|
*/
|
|
523
524
|
function createVirtualPersistentObjectAttribute(attr, persistentObject, service) {
|
|
525
|
+
const internalAttr = attr;
|
|
524
526
|
const helpers = {
|
|
525
527
|
getValue() {
|
|
526
|
-
return
|
|
528
|
+
return internalAttr.value;
|
|
527
529
|
},
|
|
528
530
|
setValue(value) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
+
internalAttr.value = value;
|
|
532
|
+
internalAttr.isValueChanged = true;
|
|
531
533
|
},
|
|
532
534
|
setValidationError(error) {
|
|
533
535
|
attr.validationError = error || undefined;
|
|
@@ -539,7 +541,7 @@ function createVirtualPersistentObjectAttribute(attr, persistentObject, service)
|
|
|
539
541
|
return service;
|
|
540
542
|
}
|
|
541
543
|
};
|
|
542
|
-
return new Proxy(
|
|
544
|
+
return new Proxy(internalAttr, {
|
|
543
545
|
get(target, prop) {
|
|
544
546
|
if (prop in helpers) {
|
|
545
547
|
const value = helpers[prop];
|
|
@@ -547,8 +549,19 @@ function createVirtualPersistentObjectAttribute(attr, persistentObject, service)
|
|
|
547
549
|
}
|
|
548
550
|
return target[prop];
|
|
549
551
|
},
|
|
550
|
-
set(target, prop,
|
|
551
|
-
|
|
552
|
+
set(target, prop, newValue) {
|
|
553
|
+
if (prop === "value") {
|
|
554
|
+
const oldValue = target.value;
|
|
555
|
+
const hasChanged = oldValue instanceof Date && newValue instanceof Date
|
|
556
|
+
? oldValue.getTime() !== newValue.getTime()
|
|
557
|
+
: oldValue !== newValue;
|
|
558
|
+
if (hasChanged) {
|
|
559
|
+
target.value = newValue;
|
|
560
|
+
target.isValueChanged = true;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else
|
|
564
|
+
target[prop] = newValue;
|
|
552
565
|
return true;
|
|
553
566
|
}
|
|
554
567
|
});
|
|
@@ -616,15 +629,21 @@ function createVirtualPersistentObject(dto, service) {
|
|
|
616
629
|
return proxy;
|
|
617
630
|
}
|
|
618
631
|
/**
|
|
619
|
-
* Unwraps a VirtualPersistentObject to get
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
* @returns The underlying PersistentObjectDto
|
|
632
|
+
* Unwraps a VirtualPersistentObject to get a DTO suitable for wire transmission.
|
|
633
|
+
* Converts primitive values to service string format.
|
|
634
|
+
* Also accepts raw DTOs for recursive handling of parent/nested objects.
|
|
623
635
|
*/
|
|
624
636
|
function unwrapVirtualPersistentObject(wrapped) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
637
|
+
const dto = wrapped;
|
|
638
|
+
return {
|
|
639
|
+
...dto,
|
|
640
|
+
attributes: dto.attributes?.map(attr => ({
|
|
641
|
+
...attr,
|
|
642
|
+
value: attr.value != null ? toServiceString(attr.value, attr.type) : attr.value
|
|
643
|
+
})),
|
|
644
|
+
parent: dto.parent ? unwrapVirtualPersistentObject(dto.parent) : undefined,
|
|
645
|
+
queries: dto.queries?.map(q => unwrapVirtualQuery(q))
|
|
646
|
+
};
|
|
628
647
|
}
|
|
629
648
|
|
|
630
649
|
var _a;
|
|
@@ -851,6 +870,9 @@ class VirtualServiceHooks extends ServiceHooks {
|
|
|
851
870
|
clientAttr.tab = configAttr.tab || "";
|
|
852
871
|
clientAttr.column = configAttr.column;
|
|
853
872
|
clientAttr.columnSpan = configAttr.columnSpan;
|
|
873
|
+
// Convert incoming service string to primitive
|
|
874
|
+
if (clientAttr.value != null)
|
|
875
|
+
clientAttr.value = fromServiceString(clientAttr.value, clientAttr.type);
|
|
854
876
|
// Reference attribute properties - only set if explicitly configured
|
|
855
877
|
if (configAttr.lookup) {
|
|
856
878
|
const refAttr = clientAttr;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vidyano-labs/virtual-service",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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": "3d37759c3014945a12137766692d4501d0eb465a"
|
|
24
24
|
}
|