shogun-core 3.0.13 → 3.0.15
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 +27 -1
- package/dist/browser/shogun-core.js +103157 -84871
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +22 -16
- package/dist/core.js +18 -26
- package/dist/examples/api-test.js +273 -0
- package/dist/examples/simple-api-test.js +89 -0
- package/dist/gundb/api.js +126 -189
- package/dist/gundb/crypto.js +32 -17
- package/dist/gundb/db.js +89 -137
- package/dist/gundb/derive.js +20 -17
- package/dist/gundb/errors.js +17 -7
- package/dist/gundb/index.js +19 -3
- package/dist/gundb/rxjs.js +19 -17
- package/dist/gundb/types.js +2 -1
- package/dist/index.js +43 -12
- package/dist/interfaces/common.js +2 -1
- package/dist/interfaces/events.js +6 -2
- package/dist/interfaces/plugin.js +2 -1
- package/dist/interfaces/shogun.js +7 -4
- package/dist/managers/AuthManager.js +9 -7
- package/dist/managers/CoreInitializer.js +23 -20
- package/dist/managers/EventManager.js +7 -4
- package/dist/managers/PluginManager.js +6 -3
- package/dist/migration-test.js +13 -8
- package/dist/plugins/base.js +11 -8
- package/dist/plugins/index.js +36 -10
- package/dist/plugins/nostr/index.js +20 -4
- package/dist/plugins/nostr/nostrConnector.js +42 -36
- package/dist/plugins/nostr/nostrConnectorPlugin.js +36 -29
- package/dist/plugins/nostr/nostrSigner.js +17 -11
- package/dist/plugins/nostr/types.js +2 -1
- package/dist/plugins/oauth/index.js +7 -2
- package/dist/plugins/oauth/oauthConnector.js +75 -69
- package/dist/plugins/oauth/oauthPlugin.js +31 -27
- package/dist/plugins/oauth/types.js +2 -1
- package/dist/plugins/web3/index.js +20 -4
- package/dist/plugins/web3/types.js +2 -1
- package/dist/plugins/web3/web3Connector.js +38 -33
- package/dist/plugins/web3/web3ConnectorPlugin.js +29 -22
- package/dist/plugins/web3/web3Signer.js +24 -18
- package/dist/plugins/webauthn/index.js +19 -3
- package/dist/plugins/webauthn/types.js +5 -2
- package/dist/plugins/webauthn/webauthn.js +30 -25
- package/dist/plugins/webauthn/webauthnPlugin.js +21 -14
- package/dist/plugins/webauthn/webauthnSigner.js +20 -14
- package/dist/storage/storage.js +5 -4
- package/dist/types/events.js +8 -2
- package/dist/types/examples/api-test.d.ts +12 -0
- package/dist/types/examples/simple-api-test.d.ts +5 -0
- package/dist/types/gundb/api.d.ts +0 -26
- package/dist/types/gundb/db.d.ts +2 -35
- package/dist/types/shogun.js +7 -4
- package/dist/utils/errorHandler.js +13 -8
- package/dist/utils/eventEmitter.js +5 -2
- package/dist/utils/validation.js +14 -7
- package/package.json +2 -1
package/dist/gundb/api.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Simplified API layer to reduce complexity for common use cases
|
|
3
4
|
* Provides quick-start methods that wrap the full DataBase functionality
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.AutoQuickStart = exports.QuickStart = exports.SimpleGunAPI = void 0;
|
|
8
|
+
exports.createSimpleAPI = createSimpleAPI;
|
|
9
|
+
exports.quickStart = quickStart;
|
|
10
|
+
exports.autoQuickStart = autoQuickStart;
|
|
11
|
+
const db_1 = require("./db");
|
|
6
12
|
/**
|
|
7
13
|
* Simple API wrapper that provides common operations with minimal complexity
|
|
8
14
|
*/
|
|
9
|
-
|
|
10
|
-
db;
|
|
15
|
+
class SimpleGunAPI {
|
|
11
16
|
constructor(db) {
|
|
12
17
|
this.db = db;
|
|
13
18
|
}
|
|
@@ -162,30 +167,37 @@ export class SimpleGunAPI {
|
|
|
162
167
|
/**
|
|
163
168
|
* Quick user data operations - simplified interface
|
|
164
169
|
*/
|
|
165
|
-
// Simple user data get
|
|
170
|
+
// Simple user data get - using direct user node
|
|
166
171
|
async getUserData(path) {
|
|
167
172
|
try {
|
|
168
173
|
if (!this.isLoggedIn()) {
|
|
169
174
|
console.warn("User not logged in");
|
|
170
175
|
return null;
|
|
171
176
|
}
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
if (!this.db.user) {
|
|
178
|
+
console.warn("User node not available");
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const data = await this.db.user.get(path).once().then();
|
|
182
|
+
return data;
|
|
174
183
|
}
|
|
175
184
|
catch (error) {
|
|
176
185
|
console.warn(`Failed to get user data from ${path}:`, error);
|
|
177
186
|
return null;
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
|
-
// Simple user data put
|
|
189
|
+
// Simple user data put - using direct user node
|
|
181
190
|
async putUserData(path, data) {
|
|
182
191
|
try {
|
|
183
192
|
if (!this.isLoggedIn()) {
|
|
184
193
|
console.warn("User not logged in");
|
|
185
194
|
return false;
|
|
186
195
|
}
|
|
187
|
-
|
|
188
|
-
|
|
196
|
+
if (!this.db.user) {
|
|
197
|
+
console.warn("User node not available");
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
await this.db.user.get(path).put(data).then();
|
|
189
201
|
return true;
|
|
190
202
|
}
|
|
191
203
|
catch (error) {
|
|
@@ -193,15 +205,18 @@ export class SimpleGunAPI {
|
|
|
193
205
|
return false;
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
|
-
// Simple user data set (alternative to put)
|
|
208
|
+
// Simple user data set (alternative to put) - using direct user node
|
|
197
209
|
async setUserData(path, data) {
|
|
198
210
|
try {
|
|
199
211
|
if (!this.isLoggedIn()) {
|
|
200
212
|
console.warn("User not logged in");
|
|
201
213
|
return false;
|
|
202
214
|
}
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
if (!this.db.user) {
|
|
216
|
+
console.warn("User node not available");
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
await this.db.user.get(path).put(data).then();
|
|
205
220
|
return true;
|
|
206
221
|
}
|
|
207
222
|
catch (error) {
|
|
@@ -209,15 +224,18 @@ export class SimpleGunAPI {
|
|
|
209
224
|
return false;
|
|
210
225
|
}
|
|
211
226
|
}
|
|
212
|
-
// Simple user data remove
|
|
227
|
+
// Simple user data remove - using direct user node
|
|
213
228
|
async removeUserData(path) {
|
|
214
229
|
try {
|
|
215
230
|
if (!this.isLoggedIn()) {
|
|
216
231
|
console.warn("User not logged in");
|
|
217
232
|
return false;
|
|
218
233
|
}
|
|
219
|
-
|
|
220
|
-
|
|
234
|
+
if (!this.db.user) {
|
|
235
|
+
console.warn("User node not available");
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
await this.db.user.get(path).put(null).then();
|
|
221
239
|
return true;
|
|
222
240
|
}
|
|
223
241
|
catch (error) {
|
|
@@ -266,147 +284,6 @@ export class SimpleGunAPI {
|
|
|
266
284
|
indexedObjectToArray(indexedObj) {
|
|
267
285
|
return this.getArrayFromIndexedObject(indexedObj);
|
|
268
286
|
}
|
|
269
|
-
// Save array as indexed object in user space
|
|
270
|
-
async putUserArray(path, arr) {
|
|
271
|
-
try {
|
|
272
|
-
if (!this.isLoggedIn()) {
|
|
273
|
-
console.warn("User not logged in");
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
const indexedObject = this.getIndexedObjectFromArray(arr);
|
|
277
|
-
return await this.putUserData(path, indexedObject);
|
|
278
|
-
}
|
|
279
|
-
catch (error) {
|
|
280
|
-
console.warn(`Failed to put user array to ${path}:`, error);
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
// Get array from indexed object in user space
|
|
285
|
-
async getUserArray(path) {
|
|
286
|
-
try {
|
|
287
|
-
if (!this.isLoggedIn()) {
|
|
288
|
-
console.warn("User not logged in");
|
|
289
|
-
return [];
|
|
290
|
-
}
|
|
291
|
-
const indexedObject = await this.getUserData(path);
|
|
292
|
-
return this.getArrayFromIndexedObject(indexedObject);
|
|
293
|
-
}
|
|
294
|
-
catch (error) {
|
|
295
|
-
console.warn(`Failed to get user array from ${path}:`, error);
|
|
296
|
-
return [];
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
// Add item to user array collection
|
|
300
|
-
async addToUserArray(path, item) {
|
|
301
|
-
try {
|
|
302
|
-
if (!this.isLoggedIn()) {
|
|
303
|
-
console.warn("User not logged in");
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
// Validate item before adding
|
|
307
|
-
if (!item || typeof item !== "object" || !item.id) {
|
|
308
|
-
console.warn("Invalid item: must be an object with an id property");
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
const currentArray = await this.getUserArray(path);
|
|
312
|
-
const newArray = [...currentArray, item];
|
|
313
|
-
return await this.putUserArray(path, newArray);
|
|
314
|
-
}
|
|
315
|
-
catch (error) {
|
|
316
|
-
console.warn(`Failed to add item to user array ${path}:`, error);
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
// Remove item from user array collection
|
|
321
|
-
async removeFromUserArray(path, itemId) {
|
|
322
|
-
try {
|
|
323
|
-
if (!this.isLoggedIn()) {
|
|
324
|
-
console.warn("User not logged in");
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
const currentArray = await this.getUserArray(path);
|
|
328
|
-
const newArray = currentArray.filter((item) => item.id !== itemId);
|
|
329
|
-
return await this.putUserArray(path, newArray);
|
|
330
|
-
}
|
|
331
|
-
catch (error) {
|
|
332
|
-
console.warn(`Failed to remove item from user array ${path}:`, error);
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
// Update item in user array collection
|
|
337
|
-
async updateInUserArray(path, itemId, updates) {
|
|
338
|
-
try {
|
|
339
|
-
if (!this.isLoggedIn()) {
|
|
340
|
-
console.warn("User not logged in");
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
const currentArray = await this.getUserArray(path);
|
|
344
|
-
const newArray = currentArray.map((item) => item.id === itemId ? { ...item, ...updates } : item);
|
|
345
|
-
return await this.putUserArray(path, newArray);
|
|
346
|
-
}
|
|
347
|
-
catch (error) {
|
|
348
|
-
console.warn(`Failed to update item in user array ${path}:`, error);
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
// Save array as indexed object in global space
|
|
353
|
-
async putArray(path, arr) {
|
|
354
|
-
try {
|
|
355
|
-
const indexedObject = this.getIndexedObjectFromArray(arr);
|
|
356
|
-
return await this.put(path, indexedObject);
|
|
357
|
-
}
|
|
358
|
-
catch (error) {
|
|
359
|
-
console.warn(`Failed to put array to ${path}:`, error);
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
// Get array from indexed object in global space
|
|
364
|
-
async getArray(path) {
|
|
365
|
-
try {
|
|
366
|
-
const indexedObject = await this.get(path);
|
|
367
|
-
return this.getArrayFromIndexedObject(indexedObject);
|
|
368
|
-
}
|
|
369
|
-
catch (error) {
|
|
370
|
-
console.warn(`Failed to get array from ${path}:`, error);
|
|
371
|
-
return [];
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
// Add item to global array collection
|
|
375
|
-
async addToArray(path, item) {
|
|
376
|
-
try {
|
|
377
|
-
const currentArray = await this.getArray(path);
|
|
378
|
-
const newArray = [...currentArray, item];
|
|
379
|
-
return await this.putArray(path, newArray);
|
|
380
|
-
}
|
|
381
|
-
catch (error) {
|
|
382
|
-
console.warn(`Failed to add item to array ${path}:`, error);
|
|
383
|
-
return false;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
// Remove item from global array collection
|
|
387
|
-
async removeFromArray(path, itemId) {
|
|
388
|
-
try {
|
|
389
|
-
const currentArray = await this.getArray(path);
|
|
390
|
-
const newArray = currentArray.filter((item) => item.id !== itemId);
|
|
391
|
-
return await this.putArray(path, newArray);
|
|
392
|
-
}
|
|
393
|
-
catch (error) {
|
|
394
|
-
console.warn(`Failed to remove item from array ${path}:`, error);
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
// Update item in global array collection
|
|
399
|
-
async updateInArray(path, itemId, updates) {
|
|
400
|
-
try {
|
|
401
|
-
const currentArray = await this.getArray(path);
|
|
402
|
-
const newArray = currentArray.map((item) => item.id === itemId ? { ...item, ...updates } : item);
|
|
403
|
-
return await this.putArray(path, newArray);
|
|
404
|
-
}
|
|
405
|
-
catch (error) {
|
|
406
|
-
console.warn(`Failed to update item in array ${path}:`, error);
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
287
|
/**
|
|
411
288
|
* Path utilities
|
|
412
289
|
*/
|
|
@@ -493,140 +370,202 @@ export class SimpleGunAPI {
|
|
|
493
370
|
return null;
|
|
494
371
|
}
|
|
495
372
|
}
|
|
496
|
-
// Update user profile (common use case)
|
|
373
|
+
// Update user profile (common use case) - using direct user node
|
|
497
374
|
async updateProfile(profileData) {
|
|
498
375
|
try {
|
|
499
376
|
if (!this.isLoggedIn()) {
|
|
500
377
|
console.warn("User not logged in");
|
|
501
378
|
return false;
|
|
502
379
|
}
|
|
503
|
-
|
|
380
|
+
if (!this.db.user) {
|
|
381
|
+
console.warn("User node not available");
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
await this.db.user.get("profile").put(profileData).then();
|
|
385
|
+
return true;
|
|
504
386
|
}
|
|
505
387
|
catch (error) {
|
|
506
388
|
console.warn("Failed to update profile:", error);
|
|
507
389
|
return false;
|
|
508
390
|
}
|
|
509
391
|
}
|
|
510
|
-
// Get user profile
|
|
392
|
+
// Get user profile - using direct user node
|
|
511
393
|
async getProfile() {
|
|
512
394
|
try {
|
|
513
395
|
if (!this.isLoggedIn()) {
|
|
514
396
|
console.warn("User not logged in");
|
|
515
397
|
return null;
|
|
516
398
|
}
|
|
517
|
-
|
|
399
|
+
if (!this.db.user) {
|
|
400
|
+
console.warn("User node not available");
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
403
|
+
const profileData = await this.db.user.get("profile").once().then();
|
|
404
|
+
return profileData;
|
|
518
405
|
}
|
|
519
406
|
catch (error) {
|
|
520
407
|
console.warn("Failed to get profile:", error);
|
|
521
408
|
return null;
|
|
522
409
|
}
|
|
523
410
|
}
|
|
524
|
-
// Save user settings
|
|
411
|
+
// Save user settings - using direct user node
|
|
525
412
|
async saveSettings(settings) {
|
|
526
413
|
try {
|
|
527
414
|
if (!this.isLoggedIn()) {
|
|
528
415
|
console.warn("User not logged in");
|
|
529
416
|
return false;
|
|
530
417
|
}
|
|
531
|
-
|
|
418
|
+
if (!this.db.user) {
|
|
419
|
+
console.warn("User node not available");
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
await this.db.user.get("settings").put(settings).then();
|
|
423
|
+
return true;
|
|
532
424
|
}
|
|
533
425
|
catch (error) {
|
|
534
426
|
console.warn("Failed to save settings:", error);
|
|
535
427
|
return false;
|
|
536
428
|
}
|
|
537
429
|
}
|
|
538
|
-
// Get user settings
|
|
430
|
+
// Get user settings - using direct user node
|
|
539
431
|
async getSettings() {
|
|
540
432
|
try {
|
|
541
433
|
if (!this.isLoggedIn()) {
|
|
542
434
|
console.warn("User not logged in");
|
|
543
435
|
return null;
|
|
544
436
|
}
|
|
545
|
-
|
|
437
|
+
if (!this.db.user) {
|
|
438
|
+
console.warn("User node not available");
|
|
439
|
+
return null;
|
|
440
|
+
}
|
|
441
|
+
const settingsData = await this.db.user.get("settings").once().then();
|
|
442
|
+
return settingsData;
|
|
546
443
|
}
|
|
547
444
|
catch (error) {
|
|
548
445
|
console.warn("Failed to get settings:", error);
|
|
549
446
|
return null;
|
|
550
447
|
}
|
|
551
448
|
}
|
|
552
|
-
// Save user preferences
|
|
449
|
+
// Save user preferences - using direct user node
|
|
553
450
|
async savePreferences(preferences) {
|
|
554
451
|
try {
|
|
555
452
|
if (!this.isLoggedIn()) {
|
|
556
453
|
console.warn("User not logged in");
|
|
557
454
|
return false;
|
|
558
455
|
}
|
|
559
|
-
|
|
456
|
+
if (!this.db.user) {
|
|
457
|
+
console.warn("User node not available");
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
await this.db.user.get("preferences").put(preferences).then();
|
|
461
|
+
return true;
|
|
560
462
|
}
|
|
561
463
|
catch (error) {
|
|
562
464
|
console.warn("Failed to save preferences:", error);
|
|
563
465
|
return false;
|
|
564
466
|
}
|
|
565
467
|
}
|
|
566
|
-
// Get user preferences
|
|
468
|
+
// Get user preferences - using direct user node
|
|
567
469
|
async getPreferences() {
|
|
568
470
|
try {
|
|
569
471
|
if (!this.isLoggedIn()) {
|
|
570
472
|
console.warn("User not logged in");
|
|
571
473
|
return null;
|
|
572
474
|
}
|
|
573
|
-
|
|
475
|
+
if (!this.db.user) {
|
|
476
|
+
console.warn("User node not available");
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
const preferencesData = await this.db.user
|
|
480
|
+
.get("preferences")
|
|
481
|
+
.once()
|
|
482
|
+
.then();
|
|
483
|
+
return preferencesData;
|
|
574
484
|
}
|
|
575
485
|
catch (error) {
|
|
576
486
|
console.warn("Failed to get preferences:", error);
|
|
577
487
|
return null;
|
|
578
488
|
}
|
|
579
489
|
}
|
|
580
|
-
// Create a user collection
|
|
490
|
+
// Create a user collection - using direct user node
|
|
581
491
|
async createCollection(collectionName, items) {
|
|
582
492
|
try {
|
|
583
493
|
if (!this.isLoggedIn()) {
|
|
584
494
|
console.warn("User not logged in");
|
|
585
495
|
return false;
|
|
586
496
|
}
|
|
587
|
-
|
|
497
|
+
if (!this.db.user) {
|
|
498
|
+
console.warn("User node not available");
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
await this.db.user.get(`collections/${collectionName}`).put(items).then();
|
|
502
|
+
return true;
|
|
588
503
|
}
|
|
589
504
|
catch (error) {
|
|
590
505
|
console.warn(`Failed to create collection ${collectionName}:`, error);
|
|
591
506
|
return false;
|
|
592
507
|
}
|
|
593
508
|
}
|
|
594
|
-
// Add item to collection
|
|
509
|
+
// Add item to collection - using direct user node
|
|
595
510
|
async addToCollection(collectionName, itemId, item) {
|
|
596
511
|
try {
|
|
597
512
|
if (!this.isLoggedIn()) {
|
|
598
513
|
console.warn("User not logged in");
|
|
599
514
|
return false;
|
|
600
515
|
}
|
|
601
|
-
|
|
516
|
+
if (!this.db.user) {
|
|
517
|
+
console.warn("User node not available");
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
await this.db.user
|
|
521
|
+
.get(`collections/${collectionName}/${itemId}`)
|
|
522
|
+
.put(item)
|
|
523
|
+
.then();
|
|
524
|
+
return true;
|
|
602
525
|
}
|
|
603
526
|
catch (error) {
|
|
604
527
|
console.warn(`Failed to add item to collection ${collectionName}:`, error);
|
|
605
528
|
return false;
|
|
606
529
|
}
|
|
607
530
|
}
|
|
608
|
-
// Get collection
|
|
531
|
+
// Get collection - using direct user node
|
|
609
532
|
async getCollection(collectionName) {
|
|
610
533
|
try {
|
|
611
534
|
if (!this.isLoggedIn()) {
|
|
612
535
|
console.warn("User not logged in");
|
|
613
536
|
return null;
|
|
614
537
|
}
|
|
615
|
-
|
|
538
|
+
if (!this.db.user) {
|
|
539
|
+
console.warn("User node not available");
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
const collectionData = await this.db.user
|
|
543
|
+
.get(`collections/${collectionName}`)
|
|
544
|
+
.once()
|
|
545
|
+
.then();
|
|
546
|
+
return collectionData;
|
|
616
547
|
}
|
|
617
548
|
catch (error) {
|
|
618
549
|
console.warn(`Failed to get collection ${collectionName}:`, error);
|
|
619
550
|
return null;
|
|
620
551
|
}
|
|
621
552
|
}
|
|
622
|
-
// Remove item from collection
|
|
553
|
+
// Remove item from collection - using direct user node
|
|
623
554
|
async removeFromCollection(collectionName, itemId) {
|
|
624
555
|
try {
|
|
625
556
|
if (!this.isLoggedIn()) {
|
|
626
557
|
console.warn("User not logged in");
|
|
627
558
|
return false;
|
|
628
559
|
}
|
|
629
|
-
|
|
560
|
+
if (!this.db.user) {
|
|
561
|
+
console.warn("User node not available");
|
|
562
|
+
return false;
|
|
563
|
+
}
|
|
564
|
+
await this.db.user
|
|
565
|
+
.get(`collections/${collectionName}/${itemId}`)
|
|
566
|
+
.put(null)
|
|
567
|
+
.then();
|
|
568
|
+
return true;
|
|
630
569
|
}
|
|
631
570
|
catch (error) {
|
|
632
571
|
console.warn(`Failed to remove item from collection ${collectionName}:`, error);
|
|
@@ -634,20 +573,19 @@ export class SimpleGunAPI {
|
|
|
634
573
|
}
|
|
635
574
|
}
|
|
636
575
|
}
|
|
576
|
+
exports.SimpleGunAPI = SimpleGunAPI;
|
|
637
577
|
/**
|
|
638
578
|
* Factory function to create a simple API instance
|
|
639
579
|
*/
|
|
640
|
-
|
|
580
|
+
function createSimpleAPI(db) {
|
|
641
581
|
return new SimpleGunAPI(db);
|
|
642
582
|
}
|
|
643
583
|
/**
|
|
644
584
|
* Quick start helper - creates a simple API with minimal configuration
|
|
645
585
|
*/
|
|
646
|
-
|
|
647
|
-
db;
|
|
648
|
-
simpleAPI;
|
|
586
|
+
class QuickStart {
|
|
649
587
|
constructor(gunInstance, appScope = "shogun") {
|
|
650
|
-
this.db = new DataBase(gunInstance, appScope);
|
|
588
|
+
this.db = new db_1.DataBase(gunInstance, appScope);
|
|
651
589
|
this.simpleAPI = new SimpleGunAPI(this.db);
|
|
652
590
|
}
|
|
653
591
|
// Initialize the database
|
|
@@ -663,14 +601,12 @@ export class QuickStart {
|
|
|
663
601
|
return this.db;
|
|
664
602
|
}
|
|
665
603
|
}
|
|
604
|
+
exports.QuickStart = QuickStart;
|
|
666
605
|
/**
|
|
667
606
|
* Auto Quick Start helper - creates a simple API with automatic Gun instance creation
|
|
668
607
|
* No need to pass a Gun instance, it creates one automatically
|
|
669
608
|
*/
|
|
670
|
-
|
|
671
|
-
db;
|
|
672
|
-
simpleAPI;
|
|
673
|
-
gunInstance;
|
|
609
|
+
class AutoQuickStart {
|
|
674
610
|
constructor(config) {
|
|
675
611
|
const gunConfig = {
|
|
676
612
|
peers: config?.peers || [],
|
|
@@ -678,9 +614,9 @@ export class AutoQuickStart {
|
|
|
678
614
|
};
|
|
679
615
|
// Remove appScope from gunConfig as it's not a Gun configuration option
|
|
680
616
|
delete gunConfig.appScope;
|
|
681
|
-
this.gunInstance = createGun(gunConfig);
|
|
617
|
+
this.gunInstance = (0, db_1.createGun)(gunConfig);
|
|
682
618
|
const appScope = config?.appScope || "shogun";
|
|
683
|
-
this.db = new DataBase(this.gunInstance, appScope);
|
|
619
|
+
this.db = new db_1.DataBase(this.gunInstance, appScope);
|
|
684
620
|
this.simpleAPI = new SimpleGunAPI(this.db);
|
|
685
621
|
}
|
|
686
622
|
// Initialize the database
|
|
@@ -700,15 +636,16 @@ export class AutoQuickStart {
|
|
|
700
636
|
return this.gunInstance;
|
|
701
637
|
}
|
|
702
638
|
}
|
|
639
|
+
exports.AutoQuickStart = AutoQuickStart;
|
|
703
640
|
/**
|
|
704
641
|
* Global helper for quick setup
|
|
705
642
|
*/
|
|
706
|
-
|
|
643
|
+
function quickStart(gunInstance, appScope) {
|
|
707
644
|
return new QuickStart(gunInstance, appScope);
|
|
708
645
|
}
|
|
709
646
|
/**
|
|
710
647
|
* Global helper for auto quick setup - creates Gun instance automatically
|
|
711
648
|
*/
|
|
712
|
-
|
|
649
|
+
function autoQuickStart(config) {
|
|
713
650
|
return new AutoQuickStart(config);
|
|
714
651
|
}
|