@prestizni-software/client-dem 0.2.22 → 0.2.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"
@@ -8,7 +8,12 @@
8
8
  "license": "ISC",
9
9
  "author": "xx0055",
10
10
  "type": "module",
11
- "main": "client.ts",
11
+ "main": "./client.js",
12
+ "module": "./client.mjs",
13
+ "types": "./client.d.ts",
14
+ "files": [
15
+ "./"
16
+ ],
12
17
  "publishConfig": {
13
18
  "access": "public",
14
19
  "registry": "https://registry.npmjs.org/"
@@ -1,82 +0,0 @@
1
- import { Socket } from "socket.io-client";
2
- import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
3
- import { createAutoUpdatedClass } from "./AutoUpdatedClientObjectClass.js";
4
- import { Constructor, IsData, LoggersType } from "./CommonTypes.js";
5
- export type WrappedInstances<T extends Record<string, Constructor<any>>> = {
6
- [K in keyof T]: AutoUpdateClientManager<T[K]>;
7
- };
8
- // ---------------------- Factory ----------------------
9
- export async function AUCManagerFactory<
10
- T extends Record<string, Constructor<any>>
11
- >(defs: T, loggers: LoggersType, socket: Socket): Promise<WrappedInstances<T>> {
12
- const classers = {} as WrappedInstances<T>;
13
- const emitter = new EventTarget();
14
- for (const key in defs) {
15
- const Model = defs[key];
16
- const c = new AutoUpdateClientManager(
17
- Model,
18
- loggers,
19
- socket,
20
- classers as any,
21
- emitter
22
- );
23
- classers[key] = c;
24
- await c.isLoadedAsync();
25
- }
26
-
27
- return classers;
28
- }
29
-
30
- export class AutoUpdateClientManager<
31
- T extends Constructor<any>
32
- > extends AutoUpdateManager<T> {
33
- constructor(
34
- classParam: T,
35
- loggers: LoggersType,
36
- socket: Socket,
37
- classers: Record<string, AutoUpdateManager<any>>,
38
- emitter: EventTarget
39
- ) {
40
- super(classParam, socket, loggers, classers, emitter);
41
- socket.emit("startup" + classParam.name, async (data: string[]) => {
42
- for (const id of data) {
43
- this.classes[id] = await this.handleGetMissingObject(id);
44
- this.classesAsArray.push(this.classes[id]);
45
- }
46
- emitter.dispatchEvent(new Event("ManagerLoaded"+this.classParam.name+this.className));
47
- });
48
- socket.on("new" + classParam.name, async (id: string) => {
49
- this.classes[id] = await this.handleGetMissingObject(id);
50
- this.classesAsArray.push(this.classes[id]);
51
- });
52
- socket.on("delete" + classParam.name, (id: string) => {
53
- this.deleteObject(id);
54
- });
55
- }
56
-
57
- protected async handleGetMissingObject(_id: string) {
58
- if (!this.classers) throw new Error(`No classers.`);
59
- return await createAutoUpdatedClass(
60
- this.classParam,
61
- this.socket,
62
- _id,
63
- this.loggers,
64
- this,
65
- this.emitter
66
- );
67
- }
68
-
69
- public async createObject(data: IsData<InstanceType<T>>) {
70
- if (!this.classers) throw new Error(`No classers.`);
71
- const object = await createAutoUpdatedClass(
72
- this.classParam,
73
- this.socket,
74
- data,
75
- this.loggers,
76
- this,
77
- this.emitter
78
- );
79
- this.classes[object._id as any] = object;
80
- return object;
81
- }
82
- }
@@ -1,83 +0,0 @@
1
- import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
2
- import { Constructor, IsData, LoggersType, SocketType } from "./CommonTypes.js";
3
- import "reflect-metadata";
4
-
5
- export abstract class AutoUpdateManager<T extends Constructor<any>> {
6
- protected classes: { [_id: string]: AutoUpdated<T> } = {};
7
- public socket: SocketType;
8
- protected classParam: T;
9
- protected properties: (keyof T)[];
10
- public readonly classers: Record<string, AutoUpdateManager<any>>;
11
- protected loggers: LoggersType = {
12
- info: () => {},
13
- debug: () => {},
14
- error: () => {},
15
- warn: () => {},
16
- };
17
- protected classesAsArray: AutoUpdated<T>[] = [];
18
- protected emitter: EventTarget;
19
- private isLoaded = false;
20
- constructor(
21
- classParam: T,
22
- socket: SocketType,
23
- loggers: LoggersType,
24
- classers: Record<string, AutoUpdateManager<any>>,
25
- emitter: EventTarget
26
- ) {
27
- this.emitter = emitter;
28
- this.classers = classers;
29
- this.socket = socket;
30
- this.classParam = classParam;
31
- this.properties = Reflect.getMetadata(
32
- "props",
33
- Object.getPrototypeOf(classParam)
34
- );
35
- loggers.warn = loggers.warn ?? loggers.info;
36
- this.loggers = loggers;
37
- }
38
-
39
-
40
- public getObject(
41
- _id: string
42
- ): AutoUpdated<T> | null {
43
- return this.classes[_id];
44
- }
45
-
46
- public async isLoadedAsync(): Promise<boolean> {
47
- if (this.isLoaded) return this.isLoaded;
48
- await new Promise((resolve) => this.emitter.addEventListener("ManagerLoaded"+this.classParam.name+this.className, resolve));
49
- this.isLoaded = true;
50
- return this.isLoaded;
51
- }
52
-
53
- public async deleteObject(_id: string): Promise<void> {
54
- if (typeof this.classes[_id] === "string")
55
- this.classes[_id] = await this.handleGetMissingObject(this.classes[_id]);
56
- (this.classes[_id]).destroy();
57
- this.classesAsArray.splice(this.classesAsArray.indexOf(this.classes[_id]), 1);
58
- delete this.classes[_id];
59
- }
60
-
61
- public get objectIDs(): string[] {
62
- return Object.keys(this.classes);
63
- }
64
-
65
- public get objects(): { [_id: string]: AutoUpdated<T> | string } {
66
- return this.classes;
67
- }
68
-
69
- public get objectsAsArray(): AutoUpdated<T>[] {
70
- return this.classesAsArray;
71
- }
72
-
73
- public get className(): string {
74
- return this.classParam.name;
75
- }
76
-
77
- protected abstract handleGetMissingObject(
78
- _id: string
79
- ): Promise<AutoUpdated<T>>;
80
- public abstract createObject(
81
- data: IsData<InstanceType<T>>
82
- ): Promise<AutoUpdated<T>>;
83
- }
@@ -1,532 +0,0 @@
1
- import "reflect-metadata";
2
- import {
3
- Constructor,
4
- DeRef,
5
- InstanceOf,
6
- IsData,
7
- LoggersType,
8
- LoggersTypeInternal,
9
- Paths,
10
- PathValueOf,
11
- RefToId,
12
- ServerResponse,
13
- ServerUpdateRequest,
14
- SocketType,
15
- } from "./CommonTypes.js";
16
- import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
17
- import { ObjectId } from "bson";
18
- import { AutoUpdateClientManager } from "./AutoUpdateClientManagerClass.js";
19
-
20
- export type AutoUpdated<T extends Constructor<any>> =
21
- AutoUpdatedClientObject<T> & DeRef<InstanceOf<T>>;
22
- export async function createAutoUpdatedClass<C extends Constructor<any>>(
23
- classParam: C,
24
- socket: SocketType,
25
- data: RefToId<IsData<InstanceType<C>>> | string,
26
- loggers: LoggersType,
27
- autoClassers: AutoUpdateClientManager<any>,
28
- emitter: EventTarget
29
- ): Promise<AutoUpdated<C>> {
30
- if (typeof data !== "string")
31
- processIsRefProperties(data, classParam.prototype, undefined, [], loggers);
32
- const props = Reflect.getMetadata("props", classParam.prototype);
33
- const instance = new (class extends AutoUpdatedClientObject<C> {})(
34
- socket,
35
- data,
36
- loggers,
37
- props,
38
- classParam.name,
39
- classParam,
40
- autoClassers,
41
- emitter
42
- );
43
-
44
- await instance.isLoadedAsync();
45
-
46
- return instance as any;
47
- }
48
-
49
- export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
50
- protected readonly socket: SocketType;
51
- //protected updates: string[] = [];
52
- protected data: IsData<T>;
53
- protected readonly isServer: boolean = false;
54
- protected readonly loggers: LoggersTypeInternal = {
55
- info: () => {},
56
- debug: () => {},
57
- error: () => {},
58
- warn: () => {},
59
- };
60
- protected isLoading = false;
61
- protected readonly emitter;
62
- protected readonly properties: (keyof T)[];
63
- protected readonly className: string;
64
- protected autoClasser: AutoUpdateManager<any>;
65
- protected isLoadingReferences = false;
66
- public readonly classProp: Constructor<T>;
67
- private readonly EmitterID = new ObjectId().toHexString();
68
- private readonly loadShit = async () => {
69
- if (this.isLoaded()) {
70
- try {
71
- await this.loadForceReferences();
72
- } catch (error) {
73
- this.loggers.error(error);
74
- }
75
- this.isLoadingReferences = false;
76
-
77
- return;
78
- }
79
- this.emitter.addEventListener("loaded" + this.EmitterID, async () => {
80
- try {
81
- await this.loadForceReferences();
82
- } catch (error) {
83
- this.loggers.error(error);
84
- }
85
- this.isLoadingReferences = false;
86
- });
87
- };
88
- constructor(
89
- socket: SocketType,
90
- data: string | RefToId<IsData<T>>,
91
- loggers: LoggersType,
92
- properties: (keyof T)[],
93
- className: string,
94
- classProperty: Constructor<T>,
95
- autoClasser: AutoUpdateManager<any>,
96
- emitter: EventTarget
97
- ) {
98
- this.emitter = emitter;
99
- this.classProp = classProperty;
100
- this.isLoadingReferences = true;
101
- this.isLoading = true;
102
- this.autoClasser = autoClasser;
103
- this.className = className;
104
- this.properties = properties;
105
- this.loggers.debug = loggers.debug;
106
- this.loggers.info = loggers.info;
107
- this.loggers.error = loggers.error;
108
- this.loggers.warn = loggers.warn ?? loggers.info;
109
- this.socket = socket;
110
- if (typeof data === "string") {
111
- if (data === "")
112
- throw new Error(
113
- "Cannot create a new AutoUpdatedClientClass with an empty string for ID."
114
- );
115
- this.socket.emit(
116
- "get" + this.className + data,
117
- null,
118
- (res: ServerResponse<T>) => {
119
- if (!res.success) {
120
- this.isLoading = false;
121
- this.loggers.error("Could not load data from server:", res.message);
122
- this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
123
- return;
124
- }
125
- checkForMissingRefs<T>(
126
- res.data as any,
127
- properties,
128
- classProperty as any,
129
- autoClasser
130
- );
131
- this.data = res.data as IsData<T>;
132
- this.isLoading = false;
133
- this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
134
- }
135
- );
136
- this.data = { _id: data } as IsData<T>;
137
- } else {
138
- this.isLoading = true;
139
- checkForMissingRefs<T>(
140
- data as any,
141
- properties,
142
- classProperty as any,
143
- autoClasser
144
- );
145
- this.data = data as any;
146
-
147
- if (this.data._id === "") this.handleNewObject(data as any);
148
- else {this.isLoading = false};
149
- }
150
- if (!this.isServer) this.openSockets();
151
- this.generateSettersAndGetters();
152
- }
153
-
154
- protected handleNewObject(data: IsData<T>) {
155
- this.isLoading = true;
156
- if (!this.className)
157
- throw new Error(
158
- "Cannot create a new AutoUpdatedClientClass without a class name."
159
- );
160
- this.socket.emit("new" + this.className, data, (res: ServerResponse<T>) => {
161
- if (!res.success) {
162
- this.isLoading = false;
163
- this.loggers.error("Could not create data on server:", res.message);
164
- this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
165
- return;
166
- }
167
- checkForMissingRefs<T>(
168
- res.data as any,
169
- this.properties,
170
- this.classProp as any,
171
- this.autoClasser
172
- );
173
- this.data = res.data as IsData<T>;
174
- this.isLoading = false;
175
- this.emitter.dispatchEvent(new Event("loaded" + this.EmitterID));
176
- });
177
- }
178
-
179
- public get extractedData(): {
180
- [K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
181
- } {
182
- const extracted = Object.fromEntries(
183
- Object.entries(
184
- processIsRefProperties(this.data, this.classProp.prototype).newData
185
- ).filter(([k, v]) => typeof v !== "function")
186
- );
187
- return structuredClone(extracted) as any as {
188
- [K in keyof InstanceType<T>]: InstanceOf<InstanceType<T>>[K];
189
- };
190
- }
191
-
192
- public isLoaded(): boolean {
193
- return !this.isLoading;
194
- }
195
-
196
- public async isLoadedAsync(): Promise<boolean> {
197
- await this.loadShit();
198
- return this.isLoading
199
- ? new Promise((resolve) => {
200
- this.emitter.addEventListener("loaded" + this.EmitterID, () => {
201
- resolve(this.isLoading === false);
202
- });
203
- })
204
- : true;
205
- }
206
-
207
- private openSockets() {
208
- this.loggers.debug(`[${this.data._id}] Opening socket listeners`);
209
-
210
- this.socket.on(
211
- "update" + this.className + this.data._id,
212
- async (update: ServerUpdateRequest<T>) => {
213
- await this.handleUpdateRequest(update);
214
- }
215
- );
216
- }
217
- // Example server-side handler
218
- private async handleUpdateRequest(
219
- update: ServerUpdateRequest<T>
220
- ): Promise<ServerResponse<undefined>> {
221
- try {
222
- const path = update.key.split(".");
223
- let dataRef: any = this.data;
224
- for (let i = 0; i < path.length - 1; i++) {
225
- if (!dataRef[path[i]]) dataRef[path[i]] = {};
226
- dataRef = dataRef[path[i]];
227
- }
228
- dataRef[path.at(-1)!] = update.value;
229
-
230
- this.loggers.debug(
231
- `[${this.data._id}] Applied patch ${update.key} set to ${update.value}`
232
- );
233
-
234
- // Return success with the applied patch
235
- return { success: true, data: undefined, message: "" };
236
- } catch (error) {
237
- this.loggers.error(`[${this.data._id}] Error applying patch:`, error);
238
- return {
239
- success: false,
240
- message: "Error applying update: " + (error as Error).message,
241
- };
242
- }
243
- }
244
-
245
- private generateSettersAndGetters() {
246
- for (const key of this.properties) {
247
- if (typeof key !== "string") return;
248
-
249
- const k = key as keyof IsData<T>;
250
- const isRef = getMetadataRecursive(
251
- "isRef",
252
- this.classProp.prototype,
253
- key
254
- );
255
-
256
- Object.defineProperty(this, key, {
257
- get: () => {
258
- if (isRef)
259
- return typeof this.data[k] === "string"
260
- ? this.findReference(this.data[k] as string)
261
- : this.data[k];
262
- else return this.data[k];
263
- },
264
- set: () => {
265
- throw new Error(
266
- `Cannot set ${key} this way, use "setValue" function.`
267
- );
268
- },
269
- enumerable: true,
270
- configurable: true,
271
- });
272
- }
273
- }
274
-
275
- protected findReference(id: string): AutoUpdated<any> | undefined {
276
- for (const classer of Object.values(this.autoClasser.classers)) {
277
- const result = classer.getObject(id);
278
- if (result) return result;
279
- }
280
- }
281
-
282
- public async setValue<K extends Paths<InstanceOf<T>>>(
283
- key: K,
284
- val: PathValueOf<T, K>
285
- ): Promise<boolean> {
286
- let value = val as any;
287
- this.loggers.debug(
288
- `[${(this.data as any)._id}] Setting ${key} to ${value}`
289
- );
290
- try {
291
- if (value instanceof AutoUpdatedClientObject)
292
- value = (value as any).extractedData._id;
293
- const path = key.split(".");
294
- let obj = this.data as any;
295
- let lastClass = this as any;
296
- let lastPath = key as string;
297
- for (let i = 0; i < path.length - 1; i++) {
298
- if (
299
- typeof obj[path[i]] !== "object" ||
300
- obj[path[i]] instanceof ObjectId
301
- ) {
302
- let temp = this.resolveReference(
303
- obj[path[i]].toString()
304
- ) as AutoUpdated<any>;
305
- if (!temp) {
306
- return false;
307
- }
308
- lastClass = temp;
309
- lastPath = path.slice(i + 1).join(".");
310
- return await lastClass.setValue(lastPath, value);
311
- } else obj = obj[path[i]];
312
- }
313
-
314
- if (lastClass !== this || lastPath !== (key as any))
315
- throw new Error("???");
316
-
317
- const success = await this.setValueInternal(lastPath, value);
318
-
319
- if (!success) {
320
- return false;
321
- }
322
- const pathArr = lastPath.split(".");
323
- if (pathArr.length === 1) {
324
- (this.data as any)[key as any] = value;
325
- await this.checkAutoStatusChange();
326
- return true;
327
- }
328
- const pathMinusLast = pathArr.splice(0, 1);
329
- let ref = this as any;
330
- for (const p of pathMinusLast) {
331
- ref = ref[p];
332
- }
333
- ref[pathArr.at(-1)!] = value;
334
- await this.checkAutoStatusChange();
335
- return true;
336
- } catch (error) {
337
- this.loggers.error(error);
338
- return false;
339
- }
340
- }
341
-
342
- public getValue(key: Paths<T>) {
343
- let value: any;
344
- for (const part of key.split(".")) {
345
- if (value) value = value[part];
346
- else value = (this.data as any)[part];
347
- }
348
- return value;
349
- }
350
-
351
- protected async setValueInternal(key: string, value: any): Promise<boolean> {
352
- const update: ServerUpdateRequest<T> = this.makeUpdate(key, value);
353
- const promise = new Promise<boolean>((resolve) => {
354
- try {
355
- this.socket.emit(
356
- "update" + this.className + this.data._id,
357
- update,
358
- (res: ServerResponse<T>) => {
359
- resolve(res.success);
360
- }
361
- );
362
- } catch (error) {
363
- this.loggers.error("Error sending update:", error);
364
- resolve(false);
365
- }
366
- });
367
- return promise;
368
- }
369
-
370
- protected makeUpdate(key: string, value: any): any {
371
- const id = this.data._id.toString();
372
- return { _id: id, key, value } as any;
373
- }
374
-
375
- protected async checkAutoStatusChange() {
376
- return;
377
- }
378
-
379
- // return a properly typed AutoUpdatedClientClass (or null)
380
- // inside AutoUpdatedClientClass
381
- protected resolveReference(id: string): AutoUpdatedClientObject<any> | null {
382
- if (!this.autoClasser) throw new Error("No autoClasser");
383
- for (const autoClasser of Object.values(this.autoClasser.classers)) {
384
- const data = autoClasser.getObject(id);
385
- if (data) return data;
386
- }
387
- return null;
388
- }
389
-
390
- private async loadForceReferences(
391
- obj: any = this.data,
392
- proto: any = this.classProp.prototype
393
- ) {
394
- const props: string[] = Reflect.getMetadata("props", proto) || [];
395
-
396
- for (const key of props) {
397
- const isRef = Reflect.getMetadata("isRef", proto, key);
398
-
399
- if (isRef) {
400
- await this.handleLoadOnForced(obj, key);
401
- }
402
-
403
- // If the property itself is a nested object, check deeper
404
- if (obj[key] && typeof obj[key] === "object") {
405
- const nestedProto = Object.getPrototypeOf(obj[key]);
406
- if (nestedProto) {
407
- await this.loadForceReferences(obj[key], nestedProto);
408
- }
409
- }
410
- }
411
- }
412
-
413
- private async handleLoadOnForced(obj: any, key: string) {
414
- if (!this.autoClasser) throw new Error("No autoClassers");
415
- const refId = obj[key];
416
- if (refId) {
417
- for (const classer of Object.values(this.autoClasser.classers)) {
418
- const result = classer.getObject(refId);
419
- if (result) {
420
- obj[key] = result;
421
-
422
- // Recursively load refs inside the resolved object
423
- if (typeof result.loadForceReferences === "function") {
424
- await result.loadForceReferences();
425
- }
426
- break;
427
- }
428
- }
429
- }
430
- }
431
- public async destroy(): Promise<void> {
432
- this.socket.emit("delete" + this.className, this.data._id);
433
- this.wipeSelf();
434
- }
435
-
436
- protected wipeSelf() {
437
- for (const key of Object.keys(this.data)) {
438
- delete (this.data as any)[key];
439
- }
440
- this.loggers.info(`[${this.data._id}] ${this.className} object wiped`);
441
- }
442
- }
443
-
444
- export function processIsRefProperties(
445
- instance: any,
446
- target: any,
447
- prefix: string | null = null,
448
- allProps: string[] = [],
449
- newData = {} as any,
450
- loggers?: LoggersType
451
- ) {
452
- const props: string[] = Reflect.getMetadata("props", target) || [];
453
-
454
- for (const prop of props) {
455
- const path = prefix ? `${prefix}.${prop}` : prop;
456
- allProps.push(path);
457
- newData[prop] = instance[prop];
458
- if (Reflect.getMetadata("isRef", target, prop)) {
459
- (loggers ?? console).debug("Changing isRef:", path);
460
- newData[prop] =
461
- typeof instance[prop] === "string"
462
- ? instance[prop]
463
- : instance[prop]?._id;
464
- }
465
-
466
- const type = Reflect.getMetadata("design:type", target, prop);
467
- if (type?.prototype) {
468
- const nestedProps = Reflect.getMetadata("props", type.prototype);
469
- if (nestedProps && instance[prop]) {
470
- newData[prop] = processIsRefProperties(
471
- instance[prop],
472
- type.prototype,
473
- path,
474
- allProps,
475
- undefined,
476
- loggers
477
- ).newData;
478
- }
479
- }
480
- }
481
- return { allProps, newData };
482
- }
483
-
484
- export function getMetadataRecursive(
485
- metaKey: string,
486
- proto: any,
487
- prop: string
488
- ) {
489
- while (proto) {
490
- const meta = Reflect.getMetadata(metaKey, proto, prop);
491
- if (meta !== undefined) return meta;
492
- proto = Object.getPrototypeOf(proto);
493
- }
494
- return undefined;
495
- }
496
-
497
- function checkForMissingRefs<C extends Constructor<any>>(
498
- data: IsData<InstanceType<C>>,
499
- props: any,
500
- classParam: C,
501
- autoClassers: AutoUpdateManager<any>
502
- ) {
503
- if (typeof data !== "string") {
504
- const entryKeys = Object.keys(data);
505
- for (const prop of props) {
506
- if (
507
- !entryKeys.includes(prop.toString()) &&
508
- getMetadataRecursive("isRef", classParam.prototype, prop.toString())
509
- ) {
510
- findMissingObjectReference(data, prop, autoClassers.classers);
511
- }
512
- }
513
- }
514
- }
515
- function findMissingObjectReference(
516
- data: any,
517
- prop: any,
518
- autoClassers: { [key: string]: AutoUpdateManager<any> }
519
- ) {
520
- for (const ac of Object.values(autoClassers)) {
521
- for (const obj of ac.objectsAsArray) {
522
- const found = Object.values(obj.extractedData).find((value) =>
523
- Array.isArray(value) ? value.includes(data._id) : value === data._id
524
- );
525
- if (found) {
526
- data[prop] = obj._id;
527
- return;
528
- }
529
- }
530
- }
531
- console.log("a");
532
- }
package/CHANGELOG.md DELETED
@@ -1,55 +0,0 @@
1
- # Changelog
2
-
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
-
5
- ### [0.2.22](https://github.com/Prestizni-Software/client-dem/compare/v0.2.21...v0.2.22) (2025-11-10)
6
-
7
- ### [0.2.21](https://github.com/Prestizni-Software/client-dem/compare/v0.2.20...v0.2.21) (2025-11-10)
8
-
9
- ### [0.2.20](https://github.com/Prestizni-Software/client-dem/compare/v0.2.19...v0.2.20) (2025-11-10)
10
-
11
- ### [0.2.19](https://github.com/Prestizni-Software/client-dem/compare/v0.2.18...v0.2.19) (2025-11-10)
12
-
13
- ### [0.2.18](https://github.com/Prestizni-Software/client-dem/compare/v0.2.17...v0.2.18) (2025-11-10)
14
-
15
- ### [0.2.17](https://github.com/Prestizni-Software/client-dem/compare/v0.2.16...v0.2.17) (2025-11-10)
16
-
17
- ### [0.2.16](https://github.com/Prestizni-Software/client-dem/compare/v0.2.15...v0.2.16) (2025-11-10)
18
-
19
- ### [0.2.15](https://github.com/Prestizni-Software/client-dem/compare/v0.2.14...v0.2.15) (2025-11-10)
20
-
21
- ### [0.2.14](https://github.com/Prestizni-Software/client-dem/compare/v0.2.13...v0.2.14) (2025-11-06)
22
-
23
- ### [0.2.13](https://github.com/Prestizni-Software/client-dem/compare/v0.2.12...v0.2.13) (2025-11-06)
24
-
25
- ### [0.2.12](https://github.com/Prestizni-Software/client-dem/compare/v0.2.11...v0.2.12) (2025-11-06)
26
-
27
- ### [0.2.11](https://github.com/Prestizni-Software/client-dem/compare/v0.2.10...v0.2.11) (2025-11-06)
28
-
29
- ### [0.2.10](https://github.com/Prestizni-Software/client-dem/compare/v0.2.9...v0.2.10) (2025-11-06)
30
-
31
- ### [0.2.9](https://github.com/Prestizni-Software/client-dem/compare/v0.2.8...v0.2.9) (2025-11-06)
32
-
33
- ### [0.2.8](https://github.com/Prestizni-Software/client-dem/compare/v0.2.7...v0.2.8) (2025-11-06)
34
-
35
- ### [0.2.7](https://github.com/Prestizni-Software/client-dem/compare/v0.2.6...v0.2.7) (2025-11-06)
36
-
37
- ### [0.2.6](https://github.com/Prestizni-Software/client-dem/compare/v0.2.5...v0.2.6) (2025-11-06)
38
-
39
- ### [0.2.5](https://github.com/Prestizni-Software/client-dem/compare/v0.2.4...v0.2.5) (2025-11-06)
40
-
41
- ### [0.2.4](https://github.com/Prestizni-Software/client-dem/compare/v0.2.3...v0.2.4) (2025-11-06)
42
-
43
- ### [0.2.3](https://github.com/Prestizni-Software/client-dem/compare/v0.2.2...v0.2.3) (2025-11-04)
44
-
45
- ### [0.2.2](https://github.com/Prestizni-Software/client-dem/compare/v0.2.1...v0.2.2) (2025-11-04)
46
-
47
- ### [0.2.1](https://github.com/Prestizni-Software/client-dem/compare/v0.1.27...v0.2.1) (2025-11-04)
48
-
49
- ### [0.1.27](https://github.com/Prestizni-Software/client-dem/compare/v0.1.26...v0.1.27) (2025-11-04)
50
-
51
- ### 0.1.26 (2025-11-04)
52
-
53
- # Changelog
54
-
55
- 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.
package/CommonTypes.ts DELETED
@@ -1,161 +0,0 @@
1
- import { DefaultEventsMap, Server } from "socket.io";
2
- import { Socket as SocketClient } from "socket.io-client";
3
- import { ObjectId } from "bson";
4
- import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
5
- import "reflect-metadata";
6
-
7
- export type Ref<T> = string | (T extends Constructor<any> ? AutoUpdated<T> : (T & { _id: string }));
8
- export type LoggersTypeInternal = LoggersType & {
9
- warn: (...args: any[]) => void;
10
- };
11
-
12
- export type LoggersType = {
13
- info: (...args: any[]) => void;
14
- debug: (...args: any[]) => void;
15
- error: (...args: any[]) => void;
16
- warn?: (...args: any[]) => void;
17
- };
18
- export type SocketType =
19
- | SocketClient<DefaultEventsMap, DefaultEventsMap>
20
- | Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>;
21
- export type IsData<T> = T extends { _id: string | ObjectId } ? T : never;
22
- export type ServerResponse<T> =
23
- | {
24
- data: T; // in this case, the applied patch
25
- message: string;
26
- success: true;
27
- }
28
- | {
29
- data?: null;
30
- message: string;
31
- success: false;
32
- };
33
-
34
- export type ServerUpdateResponse<T> = {
35
- data: Partial<IsData<T>>;
36
- message: string;
37
- success: true;
38
- updateId: string;
39
- };
40
-
41
- export type ServerUpdateRequest<T> = {
42
- _id: string;
43
- key: string;
44
- value: any;
45
- };
46
- export function classProp(target: any, propertyKey: string) {
47
- const props = Reflect.getMetadata("props", target) || [];
48
- props.push(propertyKey);
49
- Reflect.defineMetadata("props", props, target);
50
- }
51
-
52
- export function classRef(target: any, propertyKey: string) {
53
- Reflect.defineMetadata("isRef", true, target, propertyKey);
54
- }
55
-
56
- // ---------------------- Core ----------------------
57
- export type AutoProps<T> = {
58
- readonly [K in keyof T]: T[K];
59
- };
60
-
61
- export type Constructor<T> = new (...args: any[]) => T;
62
- export type UnboxConstructor<T> = T extends new (...args: any[]) => infer I
63
- ? I
64
- : T;
65
-
66
- // ---------------------- DeRef ----------------------
67
- export type NonOptional<T> = Exclude<T, null | undefined>;
68
-
69
- export type DeRef<T> = {
70
- [K in keyof T]: T[K] extends Ref<infer U>
71
- ? NonOptional<U>
72
- : T[K] extends Ref<infer U> | null | undefined
73
- ? NonOptional<U>
74
- : NonOptional<T[K]>;
75
- };
76
-
77
- export type RefToId<T> = {
78
- [K in keyof T]: T[K] extends Ref<infer U> ? string : T[K];
79
- };
80
-
81
- // ---------------------- Instance helper ----------------------
82
- export type InstanceOf<T> = T extends Constructor<infer I> ? I : T;
83
-
84
- // Generic filter for any desired type
85
- export type NeededTypeAtPath<C extends Constructor<any>, T> = {
86
- [P in Paths<C>]: PathValueOf<C, P> extends T ? P : never;
87
- }[Paths<C>];
88
-
89
- // ---------------------- Paths ----------------------
90
-
91
- type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
92
- type StripPrototypePrefix<P extends string> = P extends "prototype"
93
- ? never
94
- : P extends `prototype.${infer Rest}`
95
- ? Rest
96
- : P;
97
-
98
- type ResolveRef<T> = T extends Ref<infer U> ? U : T;
99
- type Recurseable<T> = T extends object
100
- ? T extends Array<any> | Function
101
- ? never
102
- : T
103
- : never;
104
- type Join<K extends string, P extends string> = `${K}.${P}`;
105
- type OnlyClassKeys<T> = {
106
- [K in keyof T]: K;
107
- }[keyof T] &
108
- string;
109
- // ---------------------- Paths ----------------------
110
- export type Paths<
111
- T,
112
- Depth extends number = 5,
113
- OriginalDepth extends number = Depth
114
- > = Depth extends never
115
- ? never
116
- : {
117
- [K in OnlyClassKeys<DeRef<NonOptional<T>>>]: K extends "_id"
118
- ? StripPrototypePrefix<`${K}`>
119
- : StripPrototypePrefix<
120
- PathsHelper<K, DeRef<NonOptional<T>>[K], Depth, OriginalDepth>
121
- >;
122
- }[OnlyClassKeys<DeRef<NonOptional<T>>>];
123
-
124
- type PathsHelper<
125
- K extends string,
126
- V,
127
- Depth extends number,
128
- OriginalDepth extends number
129
- > = Recurseable<V> extends never
130
- ? `${K}`
131
- : `${K}` | Join<K, Paths<DeRef<NonOptional<V>>, Prev[Depth], OriginalDepth>>;
132
-
133
- // ---------------------- PathValueOf ----------------------
134
- type Split<S extends string> = S extends `${infer L}.${infer R}`
135
- ? [L, ...Split<R>]
136
- : [S];
137
-
138
- type PathValue<
139
- T,
140
- Parts extends readonly string[],
141
- Depth extends number = 5
142
- > = Depth extends 0
143
- ? any
144
- : Parts extends [infer K, ...infer Rest]
145
- ? K extends keyof T
146
- ? Rest extends readonly string[]
147
- ? Rest["length"] extends 0
148
- ? ResolveRef<T[K]>
149
- : PathValue<ResolveRef<T[K]>, Rest, Prev[Depth]>
150
- : never
151
- : never
152
- : T;
153
-
154
- export type PathValueOf<
155
- T,
156
- P extends string,
157
- Depth extends number = 5
158
- > = PathValue<DeRef<InstanceOf<T>>, Split<P>, Depth>;
159
-
160
- // ---------------------- Pretty ----------------------
161
- export type Pretty<T> = { [K in keyof T]: T[K] };
package/client.ts DELETED
@@ -1,11 +0,0 @@
1
- import * as AutoUpdateClientManagerClass from "./AutoUpdateClientManagerClass.js";
2
- import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass.js";
3
- import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass.js";
4
- import * as CommonTypes from "./CommonTypes.js";
5
-
6
- module.exports = {
7
- AutoUpdateClientManagerClass,
8
- AutoUpdateManagerClass,
9
- AutoUpdatedClientObjectClass,
10
- CommonTypes,
11
- };
package/tsconfig.json DELETED
@@ -1,113 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
- "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "libReplacement": true, /* Enable lib replacement. */
18
- "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19
- "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
21
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
22
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
23
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
24
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
25
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
26
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
27
-
28
- /* Modules */
29
- "module": "es2022", /* Specify what module code is generated. */
30
- "rootDir": "./", /* Specify the root folder within your source files. */
31
- "moduleResolution": "bundler", /* Specify how TypeScript looks up a file from a given module specifier. */
32
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
35
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
36
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
37
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
38
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
39
- "allowImportingTsExtensions": false, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
40
- // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
41
- // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
42
- // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
43
- // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
44
- // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
45
- "resolveJsonModule": true, /* Enable importing .json files. */
46
- // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
47
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
48
-
49
- /* JavaScript Support */
50
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
51
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
52
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
53
-
54
- /* Emit */
55
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
56
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
57
- "emitDeclarationOnly": false, /* Only output d.ts files and not JavaScript files. */
58
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
59
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60
- // "noEmit": true, /* Disable emitting files from a compilation. */
61
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
62
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
63
- // "removeComments": true, /* Disable emitting comments. */
64
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
65
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
66
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
67
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
68
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
69
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
70
- // "newLine": "crlf", /* Set the newline character for emitting files. */
71
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
72
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
73
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
74
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
75
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
76
-
77
- /* Interop Constraints */
78
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
79
- // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
80
- // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
81
- // "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
82
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
83
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
84
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
85
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
86
-
87
- /* Type Checking */
88
- "strict": true, /* Enable all strict type-checking options. */
89
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
90
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
91
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
92
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
93
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
94
- // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
95
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
96
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
97
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
98
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
99
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
100
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
101
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
102
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
103
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
104
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
105
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
106
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
107
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
108
-
109
- /* Completeness */
110
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
111
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
112
- }
113
- }