@prestizni-software/client-dem 0.9.0 → 0.9.2

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 ADDED
@@ -0,0 +1,167 @@
1
+ # DEM (Data Entity Manager)
2
+
3
+ Real-time reactive data synchronization library for TypeScript applications.
4
+
5
+ DEM connects MongoDB backend database collections to client applications through bidirectional WebSockets. Entities synchronize automatically when properties change.
6
+
7
+ ---
8
+
9
+ ## Architecture Overview
10
+
11
+ ```mermaid
12
+ flowchart TD
13
+ DB[(MongoDB Database)] <--> SrvObj["Server Object (Typegoose)"]
14
+ SrvObj <--> SrvMgr["AutoUpdateServerManager"]
15
+ SrvMgr <-->|Socket.io| CltMgr["AutoUpdateClientManager"]
16
+ CltMgr <--> CltObj["Client Object (Reactive State)"]
17
+ CltObj <--> UI["Application UI Layer"]
18
+ ```
19
+
20
+ DEM isolates responsibilities into two distinct packages:
21
+ - **`@prestizni-software/client-dem`**: Lightweight client library with zero database dependencies.
22
+ - **`@prestizni-software/server-dem`**: Server synchronization engine with MongoDB and Typegoose integration.
23
+
24
+ ---
25
+
26
+ ## Core Features
27
+
28
+ ### 1. Real-Time Synchronization
29
+ - Transmits entity property changes across WebSockets automatically.
30
+ - Generates reactive getters and setters through TypeScript decorators.
31
+ - Deduplicates concurrent update requests and network transmissions.
32
+
33
+ ### 2. Smart Lazy Loading (v0.8.0+)
34
+ - Transmits lightweight entity manifests during startup in lazy mode.
35
+ - Includes human-readable descriptors generated on the server.
36
+ - Hydrates related entity graphs on demand up to a designated depth.
37
+ - Prevents circular reference loops through internal cycle detection.
38
+
39
+ ### 3. Delta Synchronization
40
+ - Tracks changes with monotonic revision numbers.
41
+ - Sends incremental change sets after temporary disconnections.
42
+ - Restores client state from storage adapters (`IndexedDB`, `LocalStorage`, `Memory`).
43
+
44
+ ### 4. Cross-Entity References
45
+ - Resolves entity relations through `@populatedRef` decorators.
46
+ - Supports self-contained snapshot entities using raw `@classProp` attributes.
47
+
48
+ ---
49
+
50
+ ## Packages
51
+
52
+ | Package | Purpose | Dependencies |
53
+ | :--- | :--- | :--- |
54
+ | [`@prestizni-software/client-dem`](https://www.npmjs.com/package/@prestizni-software/client-dem) | Browser, Mobile, and Node client applications | Socket.io Client, BSON, EventEmitter3 |
55
+ | [`@prestizni-software/server-dem`](https://www.npmjs.com/package/@prestizni-software/server-dem) | Backend service synchronization | Typegoose, Socket.io, BSON, EventEmitter3 |
56
+
57
+ ---
58
+
59
+ ## Installation
60
+
61
+ Install the client package:
62
+ ```bash
63
+ npm install @prestizni-software/client-dem
64
+ ```
65
+
66
+ Install the server package:
67
+ ```bash
68
+ npm install @prestizni-software/server-dem
69
+ ```
70
+
71
+ ---
72
+
73
+ ## Quick Start Guide
74
+
75
+ ### Step 1: Define Server Entity and Manager
76
+
77
+ ```typescript
78
+ import {
79
+ AutoUpdatedServerObject,
80
+ classProp,
81
+ populatedRef,
82
+ initDEMServer,
83
+ } from "@prestizni-software/server-dem";
84
+
85
+ export class TaskServer extends AutoUpdatedServerObject<TaskServer> {
86
+ @classProp
87
+ public title!: string;
88
+
89
+ @classProp
90
+ public completed!: boolean;
91
+
92
+ public static override getDescriptor(data: Partial<TaskServer>): string {
93
+ return `Task: ${data.title ?? "Untitled"}`;
94
+ }
95
+ }
96
+
97
+ // Initialize server manager
98
+ const serverManagers = initDEMServer({
99
+ Task: TaskServer,
100
+ }, socketServer, mongoConnection, {
101
+ lazyLoading: true, // Enables Smart Lazy Loading
102
+ });
103
+ ```
104
+
105
+ ### Step 2: Define Client Entity and Manager
106
+
107
+ ```typescript
108
+ import {
109
+ AutoUpdatedClientObject,
110
+ classProp,
111
+ initDEMClient,
112
+ } from "@prestizni-software/client-dem";
113
+
114
+ export class TaskClient extends AutoUpdatedClientObject<TaskClient> {
115
+ @classProp
116
+ public title!: string;
117
+
118
+ @classProp
119
+ public completed!: boolean;
120
+ }
121
+
122
+ // Connect client manager
123
+ const clientManagers = initDEMClient({
124
+ Task: TaskClient,
125
+ }, socketClient, {
126
+ lazyLoading: true,
127
+ });
128
+
129
+ await clientManagers.Task.loadFromServer();
130
+ ```
131
+
132
+ ### Step 3: Access and Mutate Entities
133
+
134
+ ```typescript
135
+ // Inspect descriptors from startup manifest
136
+ const manifests = clientManagers.Task.manifest;
137
+ console.log("Available tasks:", manifests);
138
+
139
+ // Hydrate entity on demand
140
+ const task = await clientManagers.Task.loadObject(manifests[0]._id, { depth: 2 });
141
+
142
+ // Read properties synchronously
143
+ console.log("Task title:", task.title);
144
+
145
+ // Update property (broadcasts to server and all clients automatically)
146
+ await task.setValue("completed", true);
147
+ ```
148
+
149
+ ---
150
+
151
+ ## Technical Documentation
152
+
153
+ Detailed architectural guides exist in the `docs/` directory:
154
+ - [Object Loading Process](docs/LOADING_PROCESS.md)
155
+ - [ADR 0001: Smart Lazy Loading & Static Snapshots](docs/adr/0001-smart-lazy-loading-and-static-snapshots.md)
156
+ - [Delta Synchronization Architecture](docs/DELTA_SYNC_ARCHITECTURE.md)
157
+ - [Delta Synchronization User Guide](docs/DELTA_SYNC.md)
158
+ - [Database States and Error Handling](docs/ERRORS_AND_DB_STATE.md)
159
+ - [Client Population Bypass Architecture](docs/CLIENT_POPULATION.md)
160
+ - [Release Workflow Guide](docs/RELEASE_WORKFLOW.md)
161
+ - [Domain Glossary](GLOSSARY.md)
162
+
163
+ ---
164
+
165
+ ## License
166
+
167
+ MIT © Prestizni Software
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prestizni-software/client-dem",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Real-time client synchronization library for DEM",
5
5
  "type": "module",
6
6
  "main": "./client.js",
package/version.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Current version of @prestizni-software/client-dem.
3
3
  */
4
- export declare const DEM_CLIENT_VERSION = "0.9.0";
4
+ export declare const DEM_CLIENT_VERSION = "0.9.2";
5
5
  /**
6
6
  * Current version of @prestizni-software/server-dem.
7
7
  */
8
- export declare const DEM_SERVER_VERSION = "0.9.0";
8
+ export declare const DEM_SERVER_VERSION = "0.9.2";
9
9
  /**
10
10
  * Lowest client version that the server is compatible with.
11
11
  * Server patches do not increment this value unless breaking compatibility.
package/version.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Current version of @prestizni-software/client-dem.
3
3
  */
4
- export const DEM_CLIENT_VERSION = "0.9.0";
4
+ export const DEM_CLIENT_VERSION = "0.9.2";
5
5
  /**
6
6
  * Current version of @prestizni-software/server-dem.
7
7
  */
8
- export const DEM_SERVER_VERSION = "0.9.0";
8
+ export const DEM_SERVER_VERSION = "0.9.2";
9
9
  /**
10
10
  * Lowest client version that the server is compatible with.
11
11
  * Server patches do not increment this value unless breaking compatibility.