@prestizni-software/client-dem 0.2.15 → 0.2.16
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 +36 -25
- package/CHANGELOG.md +2 -0
- package/package.json +1 -1
|
@@ -39,8 +39,6 @@ export async function createAutoUpdatedClass<C extends Constructor<any>>(
|
|
|
39
39
|
classParam,
|
|
40
40
|
autoClassers,
|
|
41
41
|
emitter
|
|
42
|
-
|
|
43
|
-
|
|
44
42
|
);
|
|
45
43
|
|
|
46
44
|
await instance.isLoadedAsync();
|
|
@@ -79,7 +77,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
79
77
|
|
|
80
78
|
return;
|
|
81
79
|
}
|
|
82
|
-
this.emitter.addEventListener("loaded"+this.EmitterID, async () => {
|
|
80
|
+
this.emitter.addEventListener("loaded" + this.EmitterID, async () => {
|
|
83
81
|
try {
|
|
84
82
|
await this.loadForceReferences();
|
|
85
83
|
} catch (error) {
|
|
@@ -122,13 +120,18 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
122
120
|
if (!res.success) {
|
|
123
121
|
this.isLoading = false;
|
|
124
122
|
this.loggers.error("Could not load data from server:", res.message);
|
|
125
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
123
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
126
124
|
return;
|
|
127
125
|
}
|
|
128
|
-
checkForMissingRefs<T>(
|
|
126
|
+
checkForMissingRefs<T>(
|
|
127
|
+
res.data as any,
|
|
128
|
+
properties,
|
|
129
|
+
classProperty as any,
|
|
130
|
+
autoClassers
|
|
131
|
+
);
|
|
129
132
|
this.data = res.data as IsData<T>;
|
|
130
133
|
this.isLoading = false;
|
|
131
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
134
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
132
135
|
}
|
|
133
136
|
);
|
|
134
137
|
this.data = { _id: data } as IsData<T>;
|
|
@@ -152,12 +155,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
152
155
|
if (!res.success) {
|
|
153
156
|
this.isLoading = false;
|
|
154
157
|
this.loggers.error("Could not create data on server:", res.message);
|
|
155
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
158
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
156
159
|
return;
|
|
157
160
|
}
|
|
158
161
|
this.data = res.data as IsData<T>;
|
|
159
162
|
this.isLoading = false;
|
|
160
|
-
this.emitter.dispatchEvent(new Event("loaded"+this.EmitterID));
|
|
163
|
+
this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
|
|
161
164
|
});
|
|
162
165
|
}
|
|
163
166
|
|
|
@@ -177,7 +180,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
177
180
|
await this.loadShit();
|
|
178
181
|
return this.isLoading
|
|
179
182
|
? new Promise((resolve) => {
|
|
180
|
-
this.emitter.addEventListener("loaded"+this.EmitterID, () => {
|
|
183
|
+
this.emitter.addEventListener("loaded" + this.EmitterID, () => {
|
|
181
184
|
resolve(this.isLoading === false);
|
|
182
185
|
});
|
|
183
186
|
})
|
|
@@ -227,7 +230,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
227
230
|
if (typeof key !== "string") return;
|
|
228
231
|
|
|
229
232
|
const k = key as keyof IsData<T>;
|
|
230
|
-
const isRef =
|
|
233
|
+
const isRef = getMetadataRecursive(
|
|
231
234
|
"isRef",
|
|
232
235
|
this.classProp.prototype,
|
|
233
236
|
key
|
|
@@ -336,15 +339,6 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
|
|
|
336
339
|
return { _id: id, key, value } as any;
|
|
337
340
|
}
|
|
338
341
|
|
|
339
|
-
private getMetadataRecursive(metaKey: string, proto: any, prop: string) {
|
|
340
|
-
while (proto) {
|
|
341
|
-
const meta = Reflect.getMetadata(metaKey, proto, prop);
|
|
342
|
-
if (meta !== undefined) return meta;
|
|
343
|
-
proto = Object.getPrototypeOf(proto);
|
|
344
|
-
}
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
342
|
// return a properly typed AutoUpdatedClientClass (or null)
|
|
349
343
|
// inside AutoUpdatedClientClass
|
|
350
344
|
protected resolveReference(id: string): AutoUpdatedClientObject<any> | null {
|
|
@@ -427,7 +421,10 @@ export function processIsRefProperties(
|
|
|
427
421
|
(loggers ?? console).debug("Changing isRef:", path);
|
|
428
422
|
|
|
429
423
|
// Example: replace with a proxy or a marker object
|
|
430
|
-
instance[prop] =
|
|
424
|
+
instance[prop] =
|
|
425
|
+
typeof instance[prop] === "string"
|
|
426
|
+
? instance[prop]
|
|
427
|
+
: instance[prop]._id;
|
|
431
428
|
}
|
|
432
429
|
|
|
433
430
|
// recurse into nested objects
|
|
@@ -455,15 +452,29 @@ export function getMetadataRecursive(
|
|
|
455
452
|
return undefined;
|
|
456
453
|
}
|
|
457
454
|
|
|
458
|
-
function checkForMissingRefs<C extends Constructor<any>>(
|
|
455
|
+
function checkForMissingRefs<C extends Constructor<any>>(
|
|
456
|
+
data: IsData<InstanceType<C>>,
|
|
457
|
+
props: any,
|
|
458
|
+
classParam: C,
|
|
459
|
+
autoClassers: { [key: string]: AutoUpdateManager<any> }
|
|
460
|
+
) {
|
|
459
461
|
if (typeof data !== "string") {
|
|
460
462
|
const entryKeys = Object.keys(data);
|
|
461
463
|
for (const prop of props) {
|
|
462
|
-
if (
|
|
463
|
-
|
|
464
|
-
(
|
|
464
|
+
if (
|
|
465
|
+
!entryKeys.includes(prop.toString()) &&
|
|
466
|
+
getMetadataRecursive("isRef", classParam.prototype, prop.toString())
|
|
467
|
+
) {
|
|
468
|
+
(data as any)[prop] = Object.values(autoClassers).find((autoClasser) =>
|
|
469
|
+
autoClasser.objectsAsArray.find((object) =>
|
|
470
|
+
Object.values(object.extractedData).find((value) =>
|
|
471
|
+
Array.isArray(value)
|
|
472
|
+
? value.includes(data._id)
|
|
473
|
+
: value === data._id
|
|
474
|
+
)
|
|
475
|
+
)
|
|
465
476
|
);
|
|
466
477
|
}
|
|
467
478
|
}
|
|
468
479
|
}
|
|
469
|
-
}
|
|
480
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
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.16](https://github.com/Prestizni-Software/client-dem/compare/v0.2.15...v0.2.16) (2025-11-10)
|
|
6
|
+
|
|
5
7
|
### [0.2.15](https://github.com/Prestizni-Software/client-dem/compare/v0.2.14...v0.2.15) (2025-11-10)
|
|
6
8
|
|
|
7
9
|
### [0.2.14](https://github.com/Prestizni-Software/client-dem/compare/v0.2.13...v0.2.14) (2025-11-06)
|