@prestizni-software/client-dem 0.2.17 → 0.2.19
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/AutoUpdatedClientObjectClass.ts +45 -16
- package/CHANGELOG.md +4 -0
- package/CommonTypes.ts +4 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
LoggersTypeInternal,
|
|
9
9
|
Paths,
|
|
10
10
|
PathValueOf,
|
|
11
|
+
RefToId,
|
|
11
12
|
ServerResponse,
|
|
12
13
|
ServerUpdateRequest,
|
|
13
14
|
SocketType,
|
|
@@ -65,7 +66,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
65
66
|
protected isLoadingReferences = false;
|
|
66
67
|
public readonly classProp: Constructor<T>;
|
|
67
68
|
private readonly EmitterID = new ObjectId().toHexString();
|
|
68
|
-
|
|
69
|
+
protected unpopulatedData: RefToId<IsData<T>>;
|
|
69
70
|
private readonly loadShit = async () => {
|
|
70
71
|
if (this.isLoaded()) {
|
|
71
72
|
try {
|
|
@@ -88,7 +89,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
88
89
|
};
|
|
89
90
|
constructor(
|
|
90
91
|
socket: SocketType,
|
|
91
|
-
data: string | IsData<T
|
|
92
|
+
data: string | RefToId<IsData<T>>,
|
|
92
93
|
loggers: LoggersType,
|
|
93
94
|
properties: (keyof T)[],
|
|
94
95
|
className: string,
|
|
@@ -123,6 +124,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
123
124
|
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
127
|
+
this.unpopulatedData = res.data as any;
|
|
126
128
|
checkForMissingRefs<T>(
|
|
127
129
|
res.data as any,
|
|
128
130
|
properties,
|
|
@@ -135,10 +137,19 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
135
137
|
}
|
|
136
138
|
);
|
|
137
139
|
this.data = { _id: data } as IsData<T>;
|
|
140
|
+
this.unpopulatedData = { _id: data } as any;
|
|
138
141
|
} else {
|
|
139
142
|
this.isLoading = true;
|
|
140
|
-
|
|
141
|
-
|
|
143
|
+
checkForMissingRefs<T>(
|
|
144
|
+
data as any,
|
|
145
|
+
properties,
|
|
146
|
+
classProperty as any,
|
|
147
|
+
autoClassers
|
|
148
|
+
);
|
|
149
|
+
this.data = data as any;
|
|
150
|
+
|
|
151
|
+
this.unpopulatedData = data;
|
|
152
|
+
if (this.data._id === "") this.handleNewObject(data as any);
|
|
142
153
|
else this.isLoading = false;
|
|
143
154
|
}
|
|
144
155
|
if (!this.isServer) this.openSockets();
|
|
@@ -158,6 +169,13 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
158
169
|
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
159
170
|
return;
|
|
160
171
|
}
|
|
172
|
+
this.unpopulatedData = res.data as any;
|
|
173
|
+
checkForMissingRefs<T>(
|
|
174
|
+
res.data as any,
|
|
175
|
+
this.properties,
|
|
176
|
+
this.classProp as any,
|
|
177
|
+
this.autoClassers
|
|
178
|
+
);
|
|
161
179
|
this.data = res.data as IsData<T>;
|
|
162
180
|
this.isLoading = false;
|
|
163
181
|
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
@@ -167,10 +185,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
167
185
|
public get extractedData(): {
|
|
168
186
|
[K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
|
|
169
187
|
} {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
Object.entries(this.
|
|
188
|
+
|
|
189
|
+
const extracted = Object.fromEntries(
|
|
190
|
+
Object.entries(this.unpopulatedData).filter(([k, v]) => typeof v !== "function")
|
|
173
191
|
)
|
|
192
|
+
return structuredClone(
|
|
193
|
+
extracted
|
|
174
194
|
) as any as {
|
|
175
195
|
[K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
|
|
176
196
|
};
|
|
@@ -469,15 +489,24 @@ function checkForMissingRefs<C extends Constructor<any>>(
|
|
|
469
489
|
!entryKeys.includes(prop.toString()) &&
|
|
470
490
|
getMetadataRecursive("isRef", classParam.prototype, prop.toString())
|
|
471
491
|
) {
|
|
472
|
-
(data
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
492
|
+
findMissingObjectReference(data, prop, autoClassers);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function findMissingObjectReference(
|
|
498
|
+
data: any,
|
|
499
|
+
prop: any,
|
|
500
|
+
autoClassers: { [key: string]: AutoUpdateManager<any> }
|
|
501
|
+
) {
|
|
502
|
+
for(const ac of Object.values(autoClassers)){
|
|
503
|
+
for(const obj of ac.objectsAsArray){
|
|
504
|
+
const found = Object.values(obj.extractedData).find((value) =>
|
|
505
|
+
Array.isArray(value) ? value.includes(data._id) : value === data._id
|
|
506
|
+
)
|
|
507
|
+
if(found){
|
|
508
|
+
data[prop] = obj._id;
|
|
509
|
+
return;
|
|
481
510
|
}
|
|
482
511
|
}
|
|
483
512
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.2.19](https://github.com/Prestizni-Software/client-dem/compare/v0.2.18...v0.2.19) (2025-11-10)
|
|
6
|
+
|
|
7
|
+
### [0.2.18](https://github.com/Prestizni-Software/client-dem/compare/v0.2.17...v0.2.18) (2025-11-10)
|
|
8
|
+
|
|
5
9
|
### [0.2.17](https://github.com/Prestizni-Software/client-dem/compare/v0.2.16...v0.2.17) (2025-11-10)
|
|
6
10
|
|
|
7
11
|
### [0.2.16](https://github.com/Prestizni-Software/client-dem/compare/v0.2.15...v0.2.16) (2025-11-10)
|
package/CommonTypes.ts
CHANGED
|
@@ -74,6 +74,10 @@ export type DeRef<T> = {
|
|
|
74
74
|
: NonOptional<T[K]>;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
export type RefToId<T> = {
|
|
78
|
+
[K in keyof T]: T[K] extends Ref<infer U> ? string : T[K];
|
|
79
|
+
};
|
|
80
|
+
|
|
77
81
|
// ---------------------- Instance helper ----------------------
|
|
78
82
|
export type InstanceOf<T> = T extends Constructor<infer I> ? I : T;
|
|
79
83
|
|