@plures/unum 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Plures, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2023 Oasis Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # unum
2
+
3
+ A modern Svelte binding library for [PluresDB](https://github.com/plures/pluresdb) with full Svelte 5 compatibility.
4
+
5
+ PluresDB is published to npm as `pluresdb` and is also available as a Deno package. It provides a modern, graph-based database with real-time synchronization capabilities, inspired by and compatible with Gun.js. Version 1.3.0 includes Node.js N-API bindings for enhanced performance.
6
+
7
+ ## Features
8
+
9
+ - **Svelte 4 & 5 Compatible**: Works with both store-based and runes-based reactivity
10
+ - **Type-Safe**: Full TypeScript support with proper types
11
+ - **Action-Based**: Modern Svelte actions for DOM binding
12
+ - **Store-Based**: Writable store implementation for reactive data
13
+ - **Collection Support**: Easy handling of PluresDB collections
14
+ - **PluresDB v1.3.0**: Supports latest PluresDB with Node.js N-API bindings and better-sqlite3 compatibility
15
+
16
+ ## Installation
17
+
18
+ ### npm
19
+
20
+ ```bash
21
+ npm install unum
22
+ ```
23
+
24
+ ### Deno
25
+
26
+ ```ts
27
+ import { PluresStore } from "https://deno.land/x/unum/mod.ts";
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Svelte 4 Store-Based API
33
+
34
+ ```svelte
35
+ <script>
36
+ import { PluresStore } from 'unum';
37
+ import { GunDB } from 'pluresdb';
38
+
39
+ const db = new GunDB();
40
+
41
+ // Create a reactive store from PluresDB data
42
+ const nameStore = new PluresStore(db.get('profile').get('name'));
43
+
44
+ // Subscribe to changes
45
+ $: name = $nameStore;
46
+
47
+ // Update PluresDB data
48
+ function updateName() {
49
+ nameStore.set('New Name');
50
+ }
51
+ </script>
52
+
53
+ <input type="text" bind:value={$nameStore} />
54
+ <button on:click={updateName}>Update</button>
55
+ ```
56
+
57
+ ### Svelte 5 Runes API
58
+
59
+ ```svelte
60
+ <script>
61
+ import { usePlures } from 'unum';
62
+ import { GunDB } from 'pluresdb';
63
+
64
+ const db = new GunDB();
65
+
66
+ // Create a reactive state variable from PluresDB data
67
+ const { value: name } = usePlures(db.get('profile').get('name'));
68
+ </script>
69
+
70
+ <input type="text" bind:value={name} />
71
+ ```
72
+
73
+ ### Action-Based API (Both Svelte 4 & 5)
74
+
75
+ ```svelte
76
+ <script>
77
+ import { plures, pluresList } from 'unum';
78
+ import { GunDB } from 'pluresdb';
79
+
80
+ const db = new GunDB();
81
+ const users = db.get('users');
82
+ </script>
83
+
84
+ <!-- Simple binding -->
85
+ <input type="text" use:plures={db.get('profile').get('name')} />
86
+
87
+ <!-- List binding with template -->
88
+ <ul use:pluresList={users}>
89
+ <li data-plures-template="true">
90
+ <span name="name">User name</span>
91
+ <input type="text" name="email" placeholder="Email" />
92
+ </li>
93
+ </ul>
94
+ ```
95
+
96
+ ## API Reference
97
+
98
+ ### Stores
99
+
100
+ - `PluresStore<T>(dbChain, options?)`: Create a Svelte store from a PluresDB chain
101
+ - `createPluresStore<T>(dbChain, options?)`: Type-safe factory function
102
+
103
+ ### Runes (Svelte 5)
104
+
105
+ - `usePlures<T>(dbChain, options?)`: Create a reactive state from a PluresDB chain
106
+
107
+ ### Actions
108
+
109
+ - `plures`: Action for binding PluresDB data to HTML elements
110
+ - `pluresList`: Action for handling collections of PluresDB data items
111
+
112
+ ## License
113
+
114
+ MIT
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Initialize PluresDB instance if not already done
3
+ * Only runs in the browser
4
+ */
5
+ export function initializePlures(): () => void;
6
+ export const todosRef: import("svelte/store").Readable<any>;
7
+ export const messagesRef: import("svelte/store").Readable<any>;
8
+ export const userProfileRef: import("svelte/store").Readable<any>;
9
+ export const plures: import("svelte/store").Writable<any>;
10
+ export const db: import("svelte/store").Writable<any>;
11
+ export const gun: import("svelte/store").Writable<any>;
12
+ /**
13
+ * Initialize PluresDB instance if not already done
14
+ * Only runs in the browser
15
+ */
16
+ export function initializeGun(): () => void;
17
+ //# sourceMappingURL=GunContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GunContext.d.ts","sourceRoot":"","sources":["../src/GunContext.js"],"names":[],"mappings":"AAiFA;;;GAGG;AACH,+CA2GC;AA/KD,4DAA2E;AAC3E,+DAAiF;AACjF,kEAAuF;AAgLvF,0DAA8B;AAC9B,sDAA0B;AAG1B,uDAA2B;AAtH3B;;;GAGG;AACH,4CA2GC"}
@@ -0,0 +1,180 @@
1
+ /**
2
+ * PluresContext - Centralized PluresDB instance management
3
+ *
4
+ * This module provides a shared PluresDB instance for the entire application,
5
+ * avoiding multiple initializations across components.
6
+ *
7
+ * PluresDB is available as the 'pluresdb' package on npm.
8
+ */
9
+ import { writable, derived } from 'svelte/store';
10
+ // Check if we're in a browser environment
11
+ const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
12
+ // Store to hold the PluresDB instance
13
+ const dbStore = writable(null);
14
+ // Derived stores for common PluresDB paths
15
+ export const todosRef = derived(dbStore, $db => $db?.get('todos') || null);
16
+ export const messagesRef = derived(dbStore, $db => $db?.get('messages') || null);
17
+ export const userProfileRef = derived(dbStore, $db => $db?.get('userProfile') || null);
18
+ // Flag to prevent multiple initializations
19
+ let initialized = false;
20
+ let initializationAttempts = 0;
21
+ const MAX_ATTEMPTS = 10;
22
+ /**
23
+ * Load PluresDB from CDN dynamically if not already loaded
24
+ * Note: For production use, install pluresdb from npm instead of using CDN
25
+ */
26
+ function loadPluresScript() {
27
+ return new Promise((resolve, reject) => {
28
+ // If PluresDB is already available, resolve immediately
29
+ // PluresDB can be loaded from pluresdb package
30
+ if (typeof window !== 'undefined' && (window.PluresDB || window.GunDB || window.Gun)) {
31
+ return resolve(window.PluresDB || window.GunDB || window.Gun);
32
+ }
33
+ // Check if the script is already in the DOM
34
+ const existingScript = document.querySelector('script[src*="pluresdb"]') ||
35
+ document.querySelector('script[src*="gun.js"]');
36
+ if (existingScript) {
37
+ // Script exists but hasn't loaded yet, wait for it
38
+ existingScript.addEventListener('load', () => {
39
+ const DB = window.PluresDB || window.GunDB || window.Gun;
40
+ if (DB) {
41
+ resolve(DB);
42
+ }
43
+ else {
44
+ reject(new Error('PluresDB script loaded but not defined'));
45
+ }
46
+ });
47
+ existingScript.addEventListener('error', () => {
48
+ reject(new Error('Failed to load PluresDB script'));
49
+ });
50
+ return;
51
+ }
52
+ // Create and add the script element
53
+ // For production, use: import { GunDB } from 'pluresdb'
54
+ // Using Gun.js CDN as fallback for browser compatibility
55
+ const script = document.createElement('script');
56
+ script.src = 'https://cdn.jsdelivr.net/npm/gun/gun.js';
57
+ script.async = true;
58
+ script.addEventListener('load', () => {
59
+ const DB = window.PluresDB || window.GunDB || window.Gun;
60
+ if (DB) {
61
+ resolve(DB);
62
+ }
63
+ else {
64
+ reject(new Error('PluresDB script loaded but not defined'));
65
+ }
66
+ });
67
+ script.addEventListener('error', () => {
68
+ reject(new Error('Failed to load PluresDB script'));
69
+ });
70
+ document.head.appendChild(script);
71
+ });
72
+ }
73
+ /**
74
+ * Initialize PluresDB instance if not already done
75
+ * Only runs in the browser
76
+ */
77
+ export function initializePlures() {
78
+ if (initialized || !isBrowser)
79
+ return;
80
+ const attemptInitialization = async () => {
81
+ // Only attempt initialization if not already initialized
82
+ if (initialized)
83
+ return;
84
+ if (initializationAttempts >= MAX_ATTEMPTS) {
85
+ console.error('Failed to initialize PluresDB after multiple attempts');
86
+ return;
87
+ }
88
+ initializationAttempts++;
89
+ try {
90
+ // Ensure PluresDB is loaded (from pluresdb package or CDN)
91
+ await loadPluresScript();
92
+ const DB = window.PluresDB || window.GunDB || window.Gun;
93
+ if (DB) {
94
+ console.log('Initializing shared PluresDB instance');
95
+ // Create a single DB instance for the app with reliable storage
96
+ const db = new DB({
97
+ localStorage: true, // Use localStorage adapter
98
+ file: 'unum-demo', // Name for stored data
99
+ radisk: true, // Use RAD to ensure data persistence
100
+ multicast: false, // No multicast for this demo
101
+ peers: ['http://localhost:8765/gun'],
102
+ axe: false // Disable Axe by default
103
+ });
104
+ // Monitor all changes to the database
105
+ db.on('put', function (data) {
106
+ console.log('PluresDB PUT event:', data);
107
+ });
108
+ // Store in our Svelte store
109
+ dbStore.set(db);
110
+ initialized = true;
111
+ // Initialize collections if they don't exist
112
+ setTimeout(() => {
113
+ if (initialized && db) {
114
+ // Initialize todos collection
115
+ db.get('todos').once((data) => {
116
+ console.log('Checking todos collection:', data);
117
+ // Add a test todo if empty
118
+ if (!data || Object.keys(data).filter(k => k !== '_').length === 0) {
119
+ console.log('Initializing empty todos collection');
120
+ // Create a test todo item with explicit text field
121
+ const testId = 'test-' + Date.now();
122
+ db.get('todos').get(testId).put({
123
+ text: 'Test Todo Item - ' + new Date().toLocaleTimeString(),
124
+ completed: false,
125
+ createdAt: Date.now()
126
+ });
127
+ console.log('Added test todo with ID:', testId);
128
+ }
129
+ else {
130
+ // Verify all todo items have a text property
131
+ console.log('Todos collection exists, checking items');
132
+ db.get('todos').map().once((item, id) => {
133
+ if (id === '_')
134
+ return;
135
+ console.log(`Checking todo ${id}:`, item);
136
+ // If item exists but has no text, add a text property
137
+ if (item && (!item.text || item.text === '')) {
138
+ console.log(`Fixing missing text for todo ${id}`);
139
+ db.get('todos').get(id).put({
140
+ ...item,
141
+ text: `Todo item ${id.substring(0, 6)}`,
142
+ });
143
+ }
144
+ });
145
+ }
146
+ });
147
+ }
148
+ }, 500);
149
+ }
150
+ else if (!initialized) {
151
+ console.warn('PluresDB not available even after loading script. Retrying...');
152
+ // Retry after a delay - only if not initialized yet
153
+ setTimeout(attemptInitialization, 500);
154
+ }
155
+ }
156
+ catch (error) {
157
+ console.error('Error initializing PluresDB:', error);
158
+ // Retry after a delay - only if not initialized yet
159
+ if (!initialized) {
160
+ setTimeout(attemptInitialization, 500);
161
+ }
162
+ }
163
+ };
164
+ // Start the initialization process once
165
+ attemptInitialization();
166
+ return () => {
167
+ console.log('Cleaning up PluresDB instance');
168
+ // PluresDB doesn't have a formal cleanup method, but we can clear our reference
169
+ dbStore.set(null);
170
+ initialized = false;
171
+ initializationAttempts = 0;
172
+ };
173
+ }
174
+ // Export the db store for components to subscribe to
175
+ export const plures = dbStore;
176
+ export const db = dbStore;
177
+ // Legacy export for backward compatibility
178
+ export const gun = dbStore;
179
+ export const initializeGun = initializePlures;
180
+ //# sourceMappingURL=GunContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GunContext.js","sourceRoot":"","sources":["../src/GunContext.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjD,0CAA0C;AAC1C,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,CAAC;AAEnF,sCAAsC;AACtC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;AAE/B,2CAA2C;AAC3C,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,CAAC;AACjF,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,CAAC;AAEvF,2CA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AAC,IAAI,CAAC,+DAA+D,CAAC,CAAC;gBAC9E,oDAAoD;gBACpD,UAAU,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;YACrD,oDAAoD;YACpD,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,UAAU,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF,wCAAwC;IACxC,qBAAqB,EAAE,CAAC;IAExB,OAAO,GAAG,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;QAC7C,gFAAgF;QAChF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClB,WAAW,GAAG,KAAK,CAAC;QACpB,sBAAsB,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC;AAC9B,MAAM,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC;AAE1B,2CAA2C;AAC3C,MAAM,CAAC,MAAM,GAAG,GAAG,OAAO,CAAC;AAC3B,MAAM,CAAC,MAAM,aAAa,GAAG,gBAAgB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * unum - Svelte action bindings for PluresDB
3
+ *
4
+ * This provides a pluresList action for binding PluresDB data to the DOM.
5
+ */
6
+ /**
7
+ * Svelte action for handling PluresDB data binding in lists
8
+ *
9
+ * @example
10
+ * ```svelte
11
+ * <div use:pluresList={{ db: db.get('messages'), callback: updateMessages }}>
12
+ * <!-- List rendering based on messages array -->
13
+ * </div>
14
+ * ```
15
+ */
16
+ export function pluresList(node: any, params: any): {
17
+ update(newParams: any): void;
18
+ destroy(): void;
19
+ };
20
+ /**
21
+ * unum - Svelte action bindings for PluresDB
22
+ *
23
+ * This provides a pluresList action for binding PluresDB data to the DOM.
24
+ */
25
+ /**
26
+ * Svelte action for handling PluresDB data binding in lists
27
+ *
28
+ * @example
29
+ * ```svelte
30
+ * <div use:pluresList={{ db: db.get('messages'), callback: updateMessages }}>
31
+ * <!-- List rendering based on messages array -->
32
+ * </div>
33
+ * ```
34
+ */
35
+ export function gunList(node: any, params: any): {
36
+ update(newParams: any): void;
37
+ destroy(): void;
38
+ };
39
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH;;;EA6EC;AA7FD;;;;GAIG;AAEH;;;;;;;;;GASG;AACH;;;EA6EC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * unum - Svelte action bindings for PluresDB
3
+ *
4
+ * This provides a pluresList action for binding PluresDB data to the DOM.
5
+ */
6
+ /**
7
+ * Svelte action for handling PluresDB data binding in lists
8
+ *
9
+ * @example
10
+ * ```svelte
11
+ * <div use:pluresList={{ db: db.get('messages'), callback: updateMessages }}>
12
+ * <!-- List rendering based on messages array -->
13
+ * </div>
14
+ * ```
15
+ */
16
+ export function pluresList(node, params) {
17
+ let unsubscribe = null;
18
+ let dbRef = null;
19
+ let callback = null;
20
+ if (!params)
21
+ return;
22
+ if (params.db || params.gun) {
23
+ dbRef = params.db || params.gun; // Support both 'db' and 'gun' for compatibility
24
+ }
25
+ if (params.callback && typeof params.callback === 'function') {
26
+ callback = params.callback;
27
+ }
28
+ // Initialize subscription
29
+ function init() {
30
+ if (dbRef && typeof dbRef.map === 'function') {
31
+ // Subscribe to changes
32
+ try {
33
+ const dataMap = {};
34
+ unsubscribe = dbRef.map().on((data, key) => {
35
+ if (key === '_')
36
+ return;
37
+ // Update data map
38
+ dataMap[key] = data;
39
+ // Call callback with all data
40
+ if (callback) {
41
+ callback(dataMap);
42
+ }
43
+ });
44
+ }
45
+ catch (error) {
46
+ console.error('Error in pluresList subscription:', error);
47
+ }
48
+ }
49
+ }
50
+ // Initialize
51
+ init();
52
+ // Return action object
53
+ return {
54
+ update(newParams) {
55
+ // Cleanup old subscription
56
+ if (unsubscribe) {
57
+ try {
58
+ unsubscribe();
59
+ }
60
+ catch (error) {
61
+ console.error('Error cleaning up pluresList subscription:', error);
62
+ }
63
+ }
64
+ // Update parameters
65
+ if (newParams.db || newParams.gun) {
66
+ dbRef = newParams.db || newParams.gun;
67
+ }
68
+ if (newParams.callback && typeof newParams.callback === 'function') {
69
+ callback = newParams.callback;
70
+ }
71
+ // Reinitialize
72
+ init();
73
+ },
74
+ destroy() {
75
+ // Clean up subscription
76
+ if (unsubscribe) {
77
+ try {
78
+ unsubscribe();
79
+ }
80
+ catch (error) {
81
+ console.error('Error cleaning up pluresList subscription:', error);
82
+ }
83
+ }
84
+ }
85
+ };
86
+ }
87
+ // Legacy export for backward compatibility
88
+ export const gunList = pluresList;
89
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.js"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,IAAI,EAAE,MAAM;IACrC,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,IAAI,QAAQ,GAAG,IAAI,CAAC;IAEpB,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,IAAI,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QAC5B,KAAK,GAAG,MAAM,CAAC,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,gDAAgD;IACnF,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC7D,QAAQ,GAAG,MAAM,CAAC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,GAAG,SAAS,CAAC,QAAQ,CAAC;YAChC,CAAC;YAED,eAAe;YACf,IAAI,EAAE,CAAC;QACT,CAAC;QACD,OAAO;YACL,wBAAwB;YACxB,IAAI,WAAW,EAAE,CAAC;gBAChB,IAAI,CAAC;oBACH,WAAW,EAAE,CAAC;gBAChB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,CAAC;gBACrE,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,2CAA2C;AAC3C,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Wraps any Svelte component with PluresDB integration
3
+ *
4
+ * @param {Component} Component - The Svelte component to wrap
5
+ * @param {Object} options - Configuration options
6
+ * @param {string} options.path - The PluresDB path to store data
7
+ * @param {string} [options.id] - Optional ID for this specific instance
8
+ * @param {Object} [options.defaultData] - Default data to use if PluresDB has no data
9
+ * @returns {Component} A new component that wraps the original with PluresDB integration
10
+ */
11
+ export function gunComponent(Component: any, { path, id, defaultData }: {
12
+ path: string;
13
+ id?: string;
14
+ defaultData?: any;
15
+ }): any;
16
+ /**
17
+ * Creates a Svelte component that wraps another component with PluresDB integration
18
+ * This provides a cleaner API for creating PluresDB-powered components
19
+ *
20
+ * @param {Component} Component - The component to wrap
21
+ * @param {string} path - PluresDB path for data storage
22
+ * @param {Object} [options] - Additional options
23
+ * @param {string} [options.id] - Optional ID for this instance
24
+ * @param {Object} [options.defaultData] - Default data to use
25
+ * @returns {Component} A new Svelte component
26
+ *
27
+ * @example
28
+ * // Create a PluresDB-powered TodoApp
29
+ * import { wrapWithGun } from '$lib/unum/gunComponent';
30
+ * import TodoApp from './TodoApp.svelte';
31
+ *
32
+ * // Simple API - component knows nothing about PluresDB
33
+ * export const PluresTodοApp = wrapWithGun(TodoApp, 'todos', {
34
+ * defaultData: { items: [] }
35
+ * });
36
+ *
37
+ * // In a parent component, use it like a normal component
38
+ * <PluresTodοApp title="My Todo List" />
39
+ */
40
+ export function wrapWithGun(Component: any, path: string, options?: {
41
+ id?: string;
42
+ defaultData?: any;
43
+ }): any;
44
+ //# sourceMappingURL=gunComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gunComponent.d.ts","sourceRoot":"","sources":["../src/gunComponent.js"],"names":[],"mappings":"AASA;;;;;;;;;GASG;AACH,wEALG;IAAwB,IAAI,EAApB,MAAM;IACW,EAAE,GAAnB,MAAM;IACW,WAAW;CACpC,OA4JF;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,kDAnBW,MAAM,YAEd;IAAyB,EAAE,GAAnB,MAAM;IACW,WAAW;CACpC,OAoDF"}