@prestizni-software/client-dem 0.2.21 → 0.2.22

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.
@@ -1,7 +1,7 @@
1
1
  import { Socket } from "socket.io-client";
2
- import { AutoUpdateManager } from "./AutoUpdateManagerClass.ts";
3
- import { createAutoUpdatedClass } from "./AutoUpdatedClientObjectClass.ts";
4
- import { Constructor, IsData, LoggersType } from "./CommonTypes.ts";
2
+ import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
3
+ import { createAutoUpdatedClass } from "./AutoUpdatedClientObjectClass.js";
4
+ import { Constructor, IsData, LoggersType } from "./CommonTypes.js";
5
5
  export type WrappedInstances<T extends Record<string, Constructor<any>>> = {
6
6
  [K in keyof T]: AutoUpdateClientManager<T[K]>;
7
7
  };
@@ -61,7 +61,7 @@ export class AutoUpdateClientManager<
61
61
  this.socket,
62
62
  _id,
63
63
  this.loggers,
64
- this.classers,
64
+ this,
65
65
  this.emitter
66
66
  );
67
67
  }
@@ -73,7 +73,7 @@ export class AutoUpdateClientManager<
73
73
  this.socket,
74
74
  data,
75
75
  this.loggers,
76
- this.classers,
76
+ this,
77
77
  this.emitter
78
78
  );
79
79
  this.classes[object._id as any] = object;
@@ -1,5 +1,5 @@
1
- import { AutoUpdated } from "./AutoUpdatedClientObjectClass.ts";
2
- import { Constructor, IsData, LoggersType, SocketType } from "./CommonTypes.ts";
1
+ import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
2
+ import { Constructor, IsData, LoggersType, SocketType } from "./CommonTypes.js";
3
3
  import "reflect-metadata";
4
4
 
5
5
  export abstract class AutoUpdateManager<T extends Constructor<any>> {
@@ -7,7 +7,7 @@ export abstract class AutoUpdateManager<T extends Constructor<any>> {
7
7
  public socket: SocketType;
8
8
  protected classParam: T;
9
9
  protected properties: (keyof T)[];
10
- protected classers: Record<string, AutoUpdateManager<any>>;
10
+ public readonly classers: Record<string, AutoUpdateManager<any>>;
11
11
  protected loggers: LoggersType = {
12
12
  info: () => {},
13
13
  debug: () => {},
@@ -12,9 +12,10 @@ import {
12
12
  ServerResponse,
13
13
  ServerUpdateRequest,
14
14
  SocketType,
15
- } from "./CommonTypes.ts";
16
- import { AutoUpdateManager } from "./AutoUpdateManagerClass.ts";
15
+ } from "./CommonTypes.js";
16
+ import { AutoUpdateManager } from "./AutoUpdateManagerClass.js";
17
17
  import { ObjectId } from "bson";
18
+ import { AutoUpdateClientManager } from "./AutoUpdateClientManagerClass.js";
18
19
 
19
20
  export type AutoUpdated<T extends Constructor<any>> =
20
21
  AutoUpdatedClientObject<T> & DeRef<InstanceOf<T>>;
@@ -23,7 +24,7 @@ export async function createAutoUpdatedClass<C extends Constructor<any>>(
23
24
  socket: SocketType,
24
25
  data: RefToId<IsData<InstanceType<C>>> | string,
25
26
  loggers: LoggersType,
26
- autoClassers: { [key: string]: AutoUpdateManager<any> },
27
+ autoClassers: AutoUpdateClientManager<any>,
27
28
  emitter: EventTarget
28
29
  ): Promise<AutoUpdated<C>> {
29
30
  if (typeof data !== "string")
@@ -60,7 +61,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
60
61
  protected readonly emitter;
61
62
  protected readonly properties: (keyof T)[];
62
63
  protected readonly className: string;
63
- protected autoClassers: Record<string, AutoUpdateManager<any>>;
64
+ protected autoClasser: AutoUpdateManager<any>;
64
65
  protected isLoadingReferences = false;
65
66
  public readonly classProp: Constructor<T>;
66
67
  private readonly EmitterID = new ObjectId().toHexString();
@@ -91,14 +92,14 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
91
92
  properties: (keyof T)[],
92
93
  className: string,
93
94
  classProperty: Constructor<T>,
94
- autoClassers: Record<string, AutoUpdateManager<any>>,
95
+ autoClasser: AutoUpdateManager<any>,
95
96
  emitter: EventTarget
96
97
  ) {
97
98
  this.emitter = emitter;
98
99
  this.classProp = classProperty;
99
100
  this.isLoadingReferences = true;
100
101
  this.isLoading = true;
101
- this.autoClassers = autoClassers;
102
+ this.autoClasser = autoClasser;
102
103
  this.className = className;
103
104
  this.properties = properties;
104
105
  this.loggers.debug = loggers.debug;
@@ -125,7 +126,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
125
126
  res.data as any,
126
127
  properties,
127
128
  classProperty as any,
128
- autoClassers
129
+ autoClasser
129
130
  );
130
131
  this.data = res.data as IsData<T>;
131
132
  this.isLoading = false;
@@ -139,12 +140,12 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
139
140
  data as any,
140
141
  properties,
141
142
  classProperty as any,
142
- autoClassers
143
+ autoClasser
143
144
  );
144
145
  this.data = data as any;
145
146
 
146
147
  if (this.data._id === "") this.handleNewObject(data as any);
147
- else this.isLoading = false;
148
+ else {this.isLoading = false};
148
149
  }
149
150
  if (!this.isServer) this.openSockets();
150
151
  this.generateSettersAndGetters();
@@ -167,7 +168,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
167
168
  res.data as any,
168
169
  this.properties,
169
170
  this.classProp as any,
170
- this.autoClassers
171
+ this.autoClasser
171
172
  );
172
173
  this.data = res.data as IsData<T>;
173
174
  this.isLoading = false;
@@ -272,7 +273,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
272
273
  }
273
274
 
274
275
  protected findReference(id: string): AutoUpdated<any> | undefined {
275
- for (const classer of Object.values(this.autoClassers)) {
276
+ for (const classer of Object.values(this.autoClasser.classers)) {
276
277
  const result = classer.getObject(id);
277
278
  if (result) return result;
278
279
  }
@@ -321,6 +322,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
321
322
  const pathArr = lastPath.split(".");
322
323
  if (pathArr.length === 1) {
323
324
  (this.data as any)[key as any] = value;
325
+ await this.checkAutoStatusChange();
324
326
  return true;
325
327
  }
326
328
  const pathMinusLast = pathArr.splice(0, 1);
@@ -329,6 +331,7 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
329
331
  ref = ref[p];
330
332
  }
331
333
  ref[pathArr.at(-1)!] = value;
334
+ await this.checkAutoStatusChange();
332
335
  return true;
333
336
  } catch (error) {
334
337
  this.loggers.error(error);
@@ -336,6 +339,15 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
336
339
  }
337
340
  }
338
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
+
339
351
  protected async setValueInternal(key: string, value: any): Promise<boolean> {
340
352
  const update: ServerUpdateRequest<T> = this.makeUpdate(key, value);
341
353
  const promise = new Promise<boolean>((resolve) => {
@@ -360,11 +372,15 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
360
372
  return { _id: id, key, value } as any;
361
373
  }
362
374
 
375
+ protected async checkAutoStatusChange() {
376
+ return;
377
+ }
378
+
363
379
  // return a properly typed AutoUpdatedClientClass (or null)
364
380
  // inside AutoUpdatedClientClass
365
381
  protected resolveReference(id: string): AutoUpdatedClientObject<any> | null {
366
- if (!this.autoClassers) throw new Error("No autoClassers");
367
- for (const autoClasser of Object.values(this.autoClassers)) {
382
+ if (!this.autoClasser) throw new Error("No autoClasser");
383
+ for (const autoClasser of Object.values(this.autoClasser.classers)) {
368
384
  const data = autoClasser.getObject(id);
369
385
  if (data) return data;
370
386
  }
@@ -395,10 +411,10 @@ export abstract class AutoUpdatedClientObject<T extends Constructor<any>> {
395
411
  }
396
412
 
397
413
  private async handleLoadOnForced(obj: any, key: string) {
398
- if (!this.autoClassers) throw new Error("No autoClassers");
414
+ if (!this.autoClasser) throw new Error("No autoClassers");
399
415
  const refId = obj[key];
400
416
  if (refId) {
401
- for (const classer of Object.values(this.autoClassers)) {
417
+ for (const classer of Object.values(this.autoClasser.classers)) {
402
418
  const result = classer.getObject(refId);
403
419
  if (result) {
404
420
  obj[key] = result;
@@ -482,7 +498,7 @@ function checkForMissingRefs<C extends Constructor<any>>(
482
498
  data: IsData<InstanceType<C>>,
483
499
  props: any,
484
500
  classParam: C,
485
- autoClassers: { [key: string]: AutoUpdateManager<any> }
501
+ autoClassers: AutoUpdateManager<any>
486
502
  ) {
487
503
  if (typeof data !== "string") {
488
504
  const entryKeys = Object.keys(data);
@@ -491,7 +507,7 @@ function checkForMissingRefs<C extends Constructor<any>>(
491
507
  !entryKeys.includes(prop.toString()) &&
492
508
  getMetadataRecursive("isRef", classParam.prototype, prop.toString())
493
509
  ) {
494
- findMissingObjectReference(data, prop, autoClassers);
510
+ findMissingObjectReference(data, prop, autoClassers.classers);
495
511
  }
496
512
  }
497
513
  }
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.22](https://github.com/Prestizni-Software/client-dem/compare/v0.2.21...v0.2.22) (2025-11-10)
6
+
5
7
  ### [0.2.21](https://github.com/Prestizni-Software/client-dem/compare/v0.2.20...v0.2.21) (2025-11-10)
6
8
 
7
9
  ### [0.2.20](https://github.com/Prestizni-Software/client-dem/compare/v0.2.19...v0.2.20) (2025-11-10)
package/CommonTypes.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DefaultEventsMap, Server } from "socket.io";
2
2
  import { Socket as SocketClient } from "socket.io-client";
3
3
  import { ObjectId } from "bson";
4
- import { AutoUpdated } from "./AutoUpdatedClientObjectClass.ts";
4
+ import { AutoUpdated } from "./AutoUpdatedClientObjectClass.js";
5
5
  import "reflect-metadata";
6
6
 
7
7
  export type Ref<T> = string | (T extends Constructor<any> ? AutoUpdated<T> : (T & { _id: string }));
package/client.ts CHANGED
@@ -1,7 +1,7 @@
1
- import * as AutoUpdateClientManagerClass from "./AutoUpdateClientManagerClass.ts";
2
- import * as AutoUpdateManagerClass from "./AutoUpdateManagerClass.ts";
3
- import * as AutoUpdatedClientObjectClass from "./AutoUpdatedClientObjectClass.ts";
4
- import * as CommonTypes from "./CommonTypes.ts";
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
5
 
6
6
  module.exports = {
7
7
  AutoUpdateClientManagerClass,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "description": "An solution for when making http requests is not a good solution",
5
5
  "keywords": [
6
6
  "websockets"
package/tsconfig.json CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  /* Projects */
6
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. */
7
+ "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
8
  // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
9
  // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
10
  // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
@@ -15,8 +15,8 @@
15
15
  // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
16
  // "jsx": "preserve", /* Specify what JSX code is generated. */
17
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. */
18
+ "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19
+ "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20
20
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
21
21
  // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
22
22
  // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
@@ -26,9 +26,9 @@
26
26
  // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
27
27
 
28
28
  /* Modules */
29
- "module": "node18", /* Specify what module code is generated. */
30
- "rootDir": "./", /* Specify the root folder within your source files. */
31
- "moduleResolution": "node16", /* Specify how TypeScript looks up a file from a given module specifier. */
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
32
  // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
33
  // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
34
  // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -36,13 +36,13 @@
36
36
  // "types": [], /* Specify type package names to be included without being referenced in a source file. */
37
37
  // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
38
38
  // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
39
- "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
+ "allowImportingTsExtensions": false, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
40
40
  // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
41
41
  // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
42
42
  // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
43
43
  // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
44
44
  // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
45
- "resolveJsonModule": true, /* Enable importing .json files. */
45
+ "resolveJsonModule": true, /* Enable importing .json files. */
46
46
  // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
47
47
  // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
48
48
 
@@ -54,12 +54,12 @@
54
54
  /* Emit */
55
55
  // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
56
56
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
57
- "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
58
- "sourceMap": true, /* Create source map files for emitted JavaScript 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
59
  // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60
60
  // "noEmit": true, /* Disable emitting files from a compilation. */
61
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. */
62
+ "outDir": "./dist", /* Specify an output folder for all emitted files. */
63
63
  // "removeComments": true, /* Disable emitting comments. */
64
64
  // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
65
65
  // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */