dolphin-client 1.0.4 → 1.0.6

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 CHANGED
@@ -29,13 +29,17 @@ By breathing life back into standard HTML, we have resurrected the simplicity of
29
29
 
30
30
  ## Features
31
31
 
32
+ - **Universal Backend Compatibility**: Native out-of-the-box support for PHP (Laravel, CakePHP, WordPress) and Node.js (Express, NestJS, Fastify). Auto-extracts/injects CSRF tokens and nonces, normalizes multi-format validation error payloads directly into reactive forms, and supports HTTP method spoofing (`_method`) and subfolder base URLs automatically.
33
+ - **HTML Component Imports (`data-import`)**: Declaratively import reusable layouts (e.g. `header.html`, `footer.html`) dynamically in pure HTML with robust concurrent promise caching, nested rendering, and circular dependency checks.
34
+ - **Instant SPA Viewport Router (`data-spa`)**: Converts static pages into highly responsive Single Page Applications (SPAs) with zero manual JS. High-jacks links, swaps viewports dynamically with smooth fading transitions, and updates page titles and history navigation (`popstate`).
32
35
  - **Hookless Reactivity**: Bind topics to DOM elements via HTML data attributes—no React, Vue, or Angular state management required.
33
36
  - **Svelte-Style Templates Compiler**: Native browser compiler supporting Svelte-style loop blocks (`{#each ... as ...}`), multi-level nested conditionals (`{#if} / {:else if} / {:else}`), loop indices (`index`), optional chaining, and dynamic attribute interpolation.
34
37
  - **Unified Event Binding**: Loop-based browser event handling for values (`data-rt-push`) and actions (`data-rt-[event]` / `data-api-[event]`).
35
38
  - **Context API/Prop drilling in Pure DOM**: Crawls up the DOM tree (`getClosestContext`) to fetch parent contexts and inject parameters.
36
39
  - **REST API + Realtime Hybrid Support**: Evaluates templates (`data-rt-template`) on initial HTTP fetches (`data-api-get`) and transitions seamlessly to real-time WebSockets on connection.
37
40
  - **WebRTC Intercom Signaling**: Built-in methods to handle peer connections, track negotiation, ICE candidates, and signaling.
38
- - **Ultralight weight**: Zero external dependencies, pure browser-native runtime APIs (~39KB compressed bundle!).
41
+ - **DolphinStore JS API & React Integration**: Programmatic store query, filtering (`where`), sorting (`orderBy`), and live collection syncing with auto-REST/WS fallback. Integrates seamlessly with React (class or hook components) using native external store subscriptions.
42
+ - **Ultralight weight**: Zero external dependencies, pure browser-native runtime APIs (~47KB compressed bundle!).
39
43
 
40
44
  ---
41
45
 
@@ -177,7 +181,26 @@ Manage local stores and run complex calculations, conditions, and toggles **dire
177
181
  <button data-store-click="app.darkMode = !app.darkMode">Toggle Dark Mode</button>
178
182
  ```
179
183
 
180
- ### 5. Silent Zero-Configuration Auto-Initialization
184
+ ### 5. JavaScript Store API & React Integration
185
+ Query and filter dynamic collections programmatically in JS or sync them with React without state hooks:
186
+
187
+ ```javascript
188
+ // Access the reactive store (auto-fetches GET /users and subscribes to WS db:sync/users)
189
+ const users = dolphin.store.users;
190
+
191
+ // Dynamic client-side filtering and sorting
192
+ const activeAdmins = users.where(u => u.active && u.role === 'admin').orderBy('name', 'asc');
193
+
194
+ // Subscribe to store changes manually
195
+ const unsubscribe = dolphin.store.subscribe(() => {
196
+ console.log("Updated admin count:", activeAdmins.items.length);
197
+ });
198
+
199
+ // Clean up when no longer needed to prevent memory leaks
200
+ dolphin.store.destroy();
201
+ ```
202
+
203
+ ### 6. Silent Zero-Configuration Auto-Initialization
181
204
  When loaded via a standard `<script>` tag in browser environments, Dolphin Client automatically boots up a default client instance as `window.dolphin` on `DOMContentLoaded`.
182
205
 
183
206
  For debugging, pass `data-debug="true"` on your script tag to turn on gorgeous, color-coded logging in your developer console for all API calls, WebSocket events, and Store updates:
package/dist/api.d.ts CHANGED
@@ -12,7 +12,27 @@ export declare class APIHandler {
12
12
  del(pathOrOptions: any, options: any): any;
13
13
  request(method: any, subPath: any, body: any, options: any): any;
14
14
  requestDirect(method: any, path: any, body: any, options: any): any;
15
+ _findCSRFToken(): string;
16
+ _resolveBaseUrl(path: string): string;
17
+ _normalizeValidationErrors(errData: any): Record<string, string>;
15
18
  };
19
+ /**
20
+ * Attempts to find a CSRF token in the document (meta tags, forms, or cookies).
21
+ * Works for Laravel, CakePHP, WordPress, Express, NestJS, etc.
22
+ * @private
23
+ */
24
+ _findCSRFToken(): string | null;
25
+ /**
26
+ * Dynamically resolves the Base Path/URL from `<base href="...">` or subfolders.
27
+ * @private
28
+ */
29
+ _resolveBaseUrl(path: string): string;
30
+ /**
31
+ * Normalizes backend validation errors from major PHP and Node.js frameworks
32
+ * into a unified { [field]: message } object.
33
+ * @private
34
+ */
35
+ _normalizeValidationErrors(errData: any): Record<string, string>;
16
36
  /**
17
37
  * Intercept request for offline-first caching and queuing.
18
38
  */
package/dist/core.d.ts CHANGED
@@ -14,6 +14,8 @@ export declare class DolphinClient {
14
14
  fileHandlers: Set<any>;
15
15
  _offlineQueue: string[];
16
16
  reconnectAttempts: number;
17
+ /** @fix: Store timer ID so disconnect() can cancel pending reconnects (was: memory/logic leak) */
18
+ _reconnectTimer: ReturnType<typeof setTimeout> | null;
17
19
  _attachedListeners: {
18
20
  target: any;
19
21
  event: string;
@@ -78,7 +80,7 @@ export declare class DolphinClient {
78
80
  * @param {function(number): void} [onProgress] — progress callback (0-100)
79
81
  * @returns {Promise<void>}
80
82
  */
81
- pubFile(fileId: any, fileData: any, filename: string, onProgress: any): Promise<void>;
83
+ pubFile(fileId: any, fileData: any, filename?: string, onProgress?: any): Promise<void>;
82
84
  /** @private */
83
85
  _uint8ToBase64(uint8: any): string;
84
86
  /**