shogun-core 3.3.7 → 3.3.8

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.
@@ -99605,14 +99605,13 @@ class ShogunCore {
99605
99605
  }
99606
99606
  }
99607
99607
  exports.ShogunCore = ShogunCore;
99608
- ShogunCore.API_VERSION = "^3.0.11";
99608
+ ShogunCore.API_VERSION = "^3.3.8";
99609
99609
  // Global declarations are handled in the original core.ts file
99610
99610
  // to avoid conflicts, we only set the window properties here
99611
99611
  if (true) {
99612
- window.SHOGUN_CORE = (config) => {
99612
+ window.ShogunCore = (config) => {
99613
99613
  return new ShogunCore(config);
99614
99614
  };
99615
- window.SHOGUN_CORE_CLASS = ShogunCore;
99616
99615
  }
99617
99616
  exports["default"] = ShogunCore;
99618
99617
 
@@ -99628,8 +99627,14 @@ exports["default"] = ShogunCore;
99628
99627
  "use strict";
99629
99628
 
99630
99629
  /**
99631
- * Simplified API layer to reduce complexity for common use cases.
99632
- * Provides quick-start methods that wrap the full DataBase functionality.
99630
+ * Simplified API layer focused on valuable helper methods.
99631
+ * Provides quick-start initialization and high-level convenience methods.
99632
+ *
99633
+ * For basic operations (get, put, set, remove, auth), use DataBase directly.
99634
+ * This class provides:
99635
+ * - Quick initialization helpers (QuickStart, AutoQuickStart)
99636
+ * - Array/Object conversion utilities for GunDB
99637
+ * - High-level user data helpers (profile, settings, collections)
99633
99638
  */
99634
99639
  Object.defineProperty(exports, "__esModule", ({ value: true }));
99635
99640
  exports.AutoQuickStart = exports.QuickStart = exports.SimpleGunAPI = void 0;
@@ -99638,7 +99643,8 @@ exports.quickStart = quickStart;
99638
99643
  exports.autoQuickStart = autoQuickStart;
99639
99644
  const db_1 = __webpack_require__(/*! ./db */ "./src/gundb/db.ts");
99640
99645
  /**
99641
- * Simple API wrapper that provides common operations with minimal complexity.
99646
+ * Simple API wrapper that provides high-level helper methods.
99647
+ * For basic operations, use the DataBase instance directly via the `database` property.
99642
99648
  */
99643
99649
  class SimpleGunAPI {
99644
99650
  /**
@@ -99648,307 +99654,24 @@ class SimpleGunAPI {
99648
99654
  constructor(db) {
99649
99655
  this.db = db;
99650
99656
  }
99651
- // =========================
99652
- // Quick data operations
99653
- // =========================
99654
- /**
99655
- * Get data at a given path.
99656
- * @param path The path to retrieve data from.
99657
- * @returns The data at the path, or null if not found or on error.
99658
- */
99659
- async get(path) {
99660
- try {
99661
- const result = await this.db.getData(path);
99662
- return result;
99663
- }
99664
- catch (error) {
99665
- console.warn(`Failed to get data from ${path}:`, error);
99666
- return null;
99667
- }
99668
- }
99669
- /**
99670
- * Get the Gun node at a given path for chaining operations.
99671
- * @param path The path to the node.
99672
- * @returns The Gun node.
99673
- */
99674
- getNode(path) {
99675
- return this.db.get(path);
99676
- }
99677
- /**
99678
- * Get the Gun node at a given path for direct chaining.
99679
- * @param path The path to the node.
99680
- * @returns The Gun node.
99681
- */
99682
- node(path) {
99683
- return this.db.get(path);
99684
- }
99685
- /**
99686
- * Get a chainable wrapper for a Gun node at a given path.
99687
- * @param path The path to the node.
99688
- * @returns An object with chainable methods: get, put, set, once, then, map.
99689
- */
99690
- chain(path) {
99691
- const node = this.db.get(path);
99692
- return {
99693
- get: (subPath) => this.chain(`${path}/${subPath}`),
99694
- put: async (data) => {
99695
- try {
99696
- const result = await this.db.put(path, data);
99697
- return result;
99698
- }
99699
- catch (error) {
99700
- console.warn(`Failed to put data to ${path}:`, error);
99701
- return { err: String(error) };
99702
- }
99703
- },
99704
- set: async (data) => {
99705
- try {
99706
- const result = await this.db.set(path, data);
99707
- return result;
99708
- }
99709
- catch (error) {
99710
- console.warn(`Failed to set data to ${path}:`, error);
99711
- return { err: String(error) };
99712
- }
99713
- },
99714
- once: async () => {
99715
- try {
99716
- return await this.db.getData(path);
99717
- }
99718
- catch (error) {
99719
- console.warn(`Failed to get data from ${path}:`, error);
99720
- return null;
99721
- }
99722
- },
99723
- then: async () => {
99724
- try {
99725
- return await this.db.getData(path);
99726
- }
99727
- catch (error) {
99728
- console.warn(`Failed to get data from ${path}:`, error);
99729
- return null;
99730
- }
99731
- },
99732
- map: (callback) => {
99733
- return node.map ? node.map(callback) : null;
99734
- },
99735
- };
99736
- }
99737
- /**
99738
- * Put data at a given path.
99739
- * @param path The path to put data to.
99740
- * @param data The data to put.
99741
- * @returns The GunMessagePut result.
99742
- */
99743
- async put(path, data) {
99744
- try {
99745
- const result = await this.db.put(path, data);
99746
- return result;
99747
- }
99748
- catch (error) {
99749
- console.warn(`Failed to put data to ${path}:`, error);
99750
- return { err: String(error) };
99751
- }
99752
- }
99753
- /**
99754
- * Set data at a given path (alternative to put).
99755
- * @param path The path to set data to.
99756
- * @param data The data to set.
99757
- * @returns The GunMessagePut result.
99758
- */
99759
- async set(path, data) {
99760
- try {
99761
- const result = await this.db.set(path, data);
99762
- return result;
99763
- }
99764
- catch (error) {
99765
- console.warn(`Failed to set data to ${path}:`, error);
99766
- return { err: String(error) };
99767
- }
99768
- }
99769
- /**
99770
- * Remove data at a given path.
99771
- * @param path The path to remove data from.
99772
- * @returns The GunMessagePut result.
99773
- */
99774
- async remove(path) {
99775
- try {
99776
- const result = await this.db.remove(path);
99777
- return result;
99778
- }
99779
- catch (error) {
99780
- console.warn(`Failed to remove data from ${path}:`, error);
99781
- return { err: String(error) };
99782
- }
99783
- }
99784
- // =========================
99785
- // Quick authentication
99786
- // =========================
99787
- /**
99788
- * Log in a user.
99789
- * @param username The username.
99790
- * @param password The password.
99791
- * @returns The user info if successful, or null.
99792
- */
99793
- async login(username, password) {
99794
- try {
99795
- const result = await this.db.login(username, password);
99796
- if (result.success && result.userPub) {
99797
- return {
99798
- userPub: result.userPub,
99799
- username: result.username || username,
99800
- };
99801
- }
99802
- return null;
99803
- }
99804
- catch (error) {
99805
- console.warn(`Login failed for ${username}:`, error);
99806
- return null;
99807
- }
99808
- }
99809
- /**
99810
- * Sign up a new user.
99811
- * @param username The username.
99812
- * @param password The password.
99813
- * @returns The user info if successful, or null.
99814
- */
99815
- async signup(username, password) {
99816
- try {
99817
- const result = await this.db.signUp(username, password);
99818
- if (result.success && result.userPub) {
99819
- return {
99820
- userPub: result.userPub,
99821
- username: result.username || username,
99822
- };
99823
- }
99824
- return null;
99825
- }
99826
- catch (error) {
99827
- console.warn(`Signup failed for ${username}:`, error);
99828
- return null;
99829
- }
99830
- }
99831
- /**
99832
- * Log out the current user.
99833
- */
99834
- logout() {
99835
- this.db.logout();
99836
- }
99837
- /**
99838
- * Check if a user is currently logged in.
99839
- * @returns True if logged in, false otherwise.
99840
- */
99841
- isLoggedIn() {
99842
- return this.db.isLoggedIn();
99843
- }
99844
- // =========================
99845
- // Quick user data operations
99846
- // =========================
99847
- /**
99848
- * Get user data at a given path (requires login).
99849
- * @param path The path to the user data.
99850
- * @returns The user data, or null if not found or on error.
99851
- */
99852
- async getUserData(path) {
99853
- try {
99854
- if (!this.isLoggedIn()) {
99855
- console.warn("User not logged in");
99856
- return null;
99857
- }
99858
- if (!this.db.user) {
99859
- console.warn("User node not available");
99860
- return null;
99861
- }
99862
- const data = await this.db.user.get(path).once().then();
99863
- return data;
99864
- }
99865
- catch (error) {
99866
- console.warn(`Failed to get user data from ${path}:`, error);
99867
- return null;
99868
- }
99869
- }
99870
- /**
99871
- * Put user data at a given path (requires login).
99872
- * @param path The path to put data to.
99873
- * @param data The data to put.
99874
- * @returns True if successful, false otherwise.
99875
- */
99876
- async putUserData(path, data) {
99877
- try {
99878
- if (!this.isLoggedIn()) {
99879
- console.warn("User not logged in");
99880
- return false;
99881
- }
99882
- if (!this.db.user) {
99883
- console.warn("User node not available");
99884
- return false;
99885
- }
99886
- await this.db.user.get(path).put(data).then();
99887
- return true;
99888
- }
99889
- catch (error) {
99890
- console.warn(`Failed to put user data to ${path}:`, error);
99891
- return false;
99892
- }
99893
- }
99894
- /**
99895
- * Set user data at a given path (alternative to put, requires login).
99896
- * @param path The path to set data to.
99897
- * @param data The data to set.
99898
- * @returns True if successful, false otherwise.
99899
- */
99900
- async setUserData(path, data) {
99901
- try {
99902
- if (!this.isLoggedIn()) {
99903
- console.warn("User not logged in");
99904
- return false;
99905
- }
99906
- if (!this.db.user) {
99907
- console.warn("User node not available");
99908
- return false;
99909
- }
99910
- await this.db.user.get(path).put(data).then();
99911
- return true;
99912
- }
99913
- catch (error) {
99914
- console.warn(`Failed to set user data to ${path}:`, error);
99915
- return false;
99916
- }
99917
- }
99918
99657
  /**
99919
- * Remove user data at a given path (requires login).
99920
- * @param path The path to remove data from.
99921
- * @returns True if successful, false otherwise.
99658
+ * Get direct access to the DataBase instance for full control.
99659
+ * Use this for basic operations like get, put, set, remove, login, etc.
99922
99660
  */
99923
- async removeUserData(path) {
99924
- try {
99925
- if (!this.isLoggedIn()) {
99926
- console.warn("User not logged in");
99927
- return false;
99928
- }
99929
- if (!this.db.user) {
99930
- console.warn("User node not available");
99931
- return false;
99932
- }
99933
- await this.db.user.get(path).put(null).then();
99934
- return true;
99935
- }
99936
- catch (error) {
99937
- console.warn(`Failed to remove user data from ${path}:`, error);
99938
- return false;
99939
- }
99661
+ get database() {
99662
+ return this.db;
99940
99663
  }
99941
99664
  // =========================
99942
99665
  // Array utilities for GunDB
99943
99666
  // =========================
99944
99667
  /**
99945
99668
  * Convert an array to an indexed object for GunDB storage.
99669
+ * GunDB doesn't store arrays natively, so this converts them to objects indexed by ID.
99946
99670
  * Example: [{id: '1', ...}, {id: '2', ...}] => { "1": {...}, "2": {...} }
99947
- * @param arr The array to convert.
99948
- * @returns The indexed object.
99949
- * @private
99671
+ * @param arr The array to convert (each item must have an 'id' property).
99672
+ * @returns The indexed object suitable for GunDB storage.
99950
99673
  */
99951
- getIndexedObjectFromArray(arr) {
99674
+ arrayToIndexedObject(arr) {
99952
99675
  // Filter out null/undefined items and ensure they have valid id
99953
99676
  const validItems = (arr || []).filter((item) => item &&
99954
99677
  typeof item === "object" &&
@@ -99963,12 +99686,12 @@ class SimpleGunAPI {
99963
99686
  }
99964
99687
  /**
99965
99688
  * Convert an indexed object back to an array.
99689
+ * Reverses the arrayToIndexedObject conversion.
99966
99690
  * Example: { "1": {...}, "2": {...} } => [{id: '1', ...}, {id: '2', ...}]
99967
99691
  * @param indexedObj The indexed object to convert.
99968
- * @returns The array.
99969
- * @private
99692
+ * @returns The array of items.
99970
99693
  */
99971
- getArrayFromIndexedObject(indexedObj) {
99694
+ indexedObjectToArray(indexedObj) {
99972
99695
  if (!indexedObj || typeof indexedObj !== "object") {
99973
99696
  return [];
99974
99697
  }
@@ -99978,109 +99701,17 @@ class SimpleGunAPI {
99978
99701
  // Filter out null/undefined values and ensure they are valid objects
99979
99702
  return Object.values(cleanObj).filter((item) => item && typeof item === "object");
99980
99703
  }
99981
- /**
99982
- * Convert an array to an indexed object for GunDB storage (public method).
99983
- * @param arr The array to convert.
99984
- * @returns The indexed object.
99985
- */
99986
- arrayToIndexedObject(arr) {
99987
- return this.getIndexedObjectFromArray(arr);
99988
- }
99989
- /**
99990
- * Convert an indexed object to an array (public method).
99991
- * @param indexedObj The indexed object to convert.
99992
- * @returns The array.
99993
- */
99994
- indexedObjectToArray(indexedObj) {
99995
- return this.getArrayFromIndexedObject(indexedObj);
99996
- }
99997
99704
  // =========================
99998
- // Path utilities
99705
+ // High-level user data helpers
99999
99706
  // =========================
100000
99707
  /**
100001
- * Get the GunDB user node at a given path (requires login).
100002
- * Useful for advanced operations that need direct GunDB node access.
100003
- * @param path The path to the user node.
100004
- * @returns The Gun node.
100005
- * @throws If not logged in.
100006
- */
100007
- getUserNode(path) {
100008
- if (!this.isLoggedIn()) {
100009
- throw new Error("User not logged in");
100010
- }
100011
- // Use the database's path deconstruction
100012
- return this.db.getUser().get(path);
100013
- }
100014
- /**
100015
- * Get the GunDB global node at a given path.
100016
- * Useful for advanced operations that need direct GunDB node access.
100017
- * @param path The path to the global node.
100018
- * @returns The Gun node.
99708
+ * Get all user data (returns user's entire data tree).
99709
+ * Requires user to be logged in.
99710
+ * @returns The complete user data tree, or null if not logged in or on error.
100019
99711
  */
100020
- getGlobalNode(path) {
100021
- // Use the database's path deconstruction
100022
- return this.db.get(path);
100023
- }
100024
- // =========================
100025
- // Quick utility methods
100026
- // =========================
100027
- /**
100028
- * Get the current user info.
100029
- * @returns The current user info, or null if not logged in.
100030
- */
100031
- getCurrentUser() {
100032
- const user = this.db.getCurrentUser();
100033
- if (user) {
100034
- return {
100035
- pub: user.pub,
100036
- username: user.alias,
100037
- };
100038
- }
100039
- return null;
100040
- }
100041
- /**
100042
- * Check if a user exists by alias.
100043
- * @param alias The user alias.
100044
- * @returns True if the user exists, false otherwise.
100045
- */
100046
- async userExists(alias) {
100047
- try {
100048
- const user = await this.db.getUserByAlias(alias);
100049
- return user !== null;
100050
- }
100051
- catch (error) {
100052
- console.warn(`Failed to check if user exists: ${alias}`, error);
100053
- return false;
100054
- }
100055
- }
100056
- /**
100057
- * Get user info by alias.
100058
- * @param alias The user alias.
100059
- * @returns The user info, or null if not found.
100060
- */
100061
- async getUser(alias) {
100062
- try {
100063
- const user = await this.db.getUserByAlias(alias);
100064
- if (user) {
100065
- return {
100066
- userPub: user.userPub,
100067
- username: user.username,
100068
- };
100069
- }
100070
- return null;
100071
- }
100072
- catch (error) {
100073
- console.warn(`Failed to get user: ${alias}`, error);
100074
- return null;
100075
- }
100076
- }
100077
- /**
100078
- * Advanced user space operations
100079
- */
100080
- // Get all user data (returns user's entire data tree)
100081
99712
  async getAllUserData() {
100082
99713
  try {
100083
- if (!this.isLoggedIn()) {
99714
+ if (!this.db.isLoggedIn()) {
100084
99715
  console.warn("User not logged in");
100085
99716
  return null;
100086
99717
  }
@@ -100102,18 +99733,20 @@ class SimpleGunAPI {
100102
99733
  return null;
100103
99734
  }
100104
99735
  }
100105
- // Update user profile (common use case) - using direct user node
99736
+ /**
99737
+ * Update user profile with common fields.
99738
+ * Provides a standardized location for user profile data.
99739
+ * @param profileData Profile data to save (name, email, bio, avatar, etc.)
99740
+ * @returns True if successful, false otherwise.
99741
+ */
100106
99742
  async updateProfile(profileData) {
100107
99743
  try {
100108
- if (!this.isLoggedIn()) {
99744
+ if (!this.db.isLoggedIn()) {
100109
99745
  console.warn("User not logged in");
100110
99746
  return false;
100111
99747
  }
100112
- if (!this.db.user) {
100113
- console.warn("User node not available");
100114
- return false;
100115
- }
100116
- await this.db.user.get("profile").put(profileData).then();
99748
+ const user = this.db.getUser();
99749
+ await user.get("profile").put(profileData).then();
100117
99750
  return true;
100118
99751
  }
100119
99752
  catch (error) {
@@ -100121,18 +99754,18 @@ class SimpleGunAPI {
100121
99754
  return false;
100122
99755
  }
100123
99756
  }
100124
- // Get user profile - using direct user node
99757
+ /**
99758
+ * Get user profile data.
99759
+ * @returns The user profile data, or null if not found or not logged in.
99760
+ */
100125
99761
  async getProfile() {
100126
99762
  try {
100127
- if (!this.isLoggedIn()) {
99763
+ if (!this.db.isLoggedIn()) {
100128
99764
  console.warn("User not logged in");
100129
99765
  return null;
100130
99766
  }
100131
- if (!this.db.user) {
100132
- console.warn("User node not available");
100133
- return null;
100134
- }
100135
- const profileData = await this.db.user.get("profile").once().then();
99767
+ const user = this.db.getUser();
99768
+ const profileData = await user.get("profile").once().then();
100136
99769
  return profileData;
100137
99770
  }
100138
99771
  catch (error) {
@@ -100140,18 +99773,20 @@ class SimpleGunAPI {
100140
99773
  return null;
100141
99774
  }
100142
99775
  }
100143
- // Save user settings - using direct user node
99776
+ /**
99777
+ * Save user settings.
99778
+ * Provides a standardized location for application settings.
99779
+ * @param settings Settings object to save.
99780
+ * @returns True if successful, false otherwise.
99781
+ */
100144
99782
  async saveSettings(settings) {
100145
99783
  try {
100146
- if (!this.isLoggedIn()) {
99784
+ if (!this.db.isLoggedIn()) {
100147
99785
  console.warn("User not logged in");
100148
99786
  return false;
100149
99787
  }
100150
- if (!this.db.user) {
100151
- console.warn("User node not available");
100152
- return false;
100153
- }
100154
- await this.db.user.get("settings").put(settings).then();
99788
+ const user = this.db.getUser();
99789
+ await user.get("settings").put(settings).then();
100155
99790
  return true;
100156
99791
  }
100157
99792
  catch (error) {
@@ -100159,18 +99794,18 @@ class SimpleGunAPI {
100159
99794
  return false;
100160
99795
  }
100161
99796
  }
100162
- // Get user settings - using direct user node
99797
+ /**
99798
+ * Get user settings.
99799
+ * @returns The user settings, or null if not found or not logged in.
99800
+ */
100163
99801
  async getSettings() {
100164
99802
  try {
100165
- if (!this.isLoggedIn()) {
99803
+ if (!this.db.isLoggedIn()) {
100166
99804
  console.warn("User not logged in");
100167
99805
  return null;
100168
99806
  }
100169
- if (!this.db.user) {
100170
- console.warn("User node not available");
100171
- return null;
100172
- }
100173
- const settingsData = await this.db.user.get("settings").once().then();
99807
+ const user = this.db.getUser();
99808
+ const settingsData = await user.get("settings").once().then();
100174
99809
  return settingsData;
100175
99810
  }
100176
99811
  catch (error) {
@@ -100178,18 +99813,20 @@ class SimpleGunAPI {
100178
99813
  return null;
100179
99814
  }
100180
99815
  }
100181
- // Save user preferences - using direct user node
99816
+ /**
99817
+ * Save user preferences.
99818
+ * Provides a standardized location for user preferences (distinct from settings).
99819
+ * @param preferences Preferences object to save.
99820
+ * @returns True if successful, false otherwise.
99821
+ */
100182
99822
  async savePreferences(preferences) {
100183
99823
  try {
100184
- if (!this.isLoggedIn()) {
99824
+ if (!this.db.isLoggedIn()) {
100185
99825
  console.warn("User not logged in");
100186
99826
  return false;
100187
99827
  }
100188
- if (!this.db.user) {
100189
- console.warn("User node not available");
100190
- return false;
100191
- }
100192
- await this.db.user.get("preferences").put(preferences).then();
99828
+ const user = this.db.getUser();
99829
+ await user.get("preferences").put(preferences).then();
100193
99830
  return true;
100194
99831
  }
100195
99832
  catch (error) {
@@ -100197,21 +99834,18 @@ class SimpleGunAPI {
100197
99834
  return false;
100198
99835
  }
100199
99836
  }
100200
- // Get user preferences - using direct user node
99837
+ /**
99838
+ * Get user preferences.
99839
+ * @returns The user preferences, or null if not found or not logged in.
99840
+ */
100201
99841
  async getPreferences() {
100202
99842
  try {
100203
- if (!this.isLoggedIn()) {
99843
+ if (!this.db.isLoggedIn()) {
100204
99844
  console.warn("User not logged in");
100205
99845
  return null;
100206
99846
  }
100207
- if (!this.db.user) {
100208
- console.warn("User node not available");
100209
- return null;
100210
- }
100211
- const preferencesData = await this.db.user
100212
- .get("preferences")
100213
- .once()
100214
- .then();
99847
+ const user = this.db.getUser();
99848
+ const preferencesData = await user.get("preferences").once().then();
100215
99849
  return preferencesData;
100216
99850
  }
100217
99851
  catch (error) {
@@ -100219,18 +99853,21 @@ class SimpleGunAPI {
100219
99853
  return null;
100220
99854
  }
100221
99855
  }
100222
- // Create a user collection - using direct user node
99856
+ /**
99857
+ * Create a user collection with initial items.
99858
+ * Provides a standardized location for user collections.
99859
+ * @param collectionName The name of the collection.
99860
+ * @param items The initial items for the collection.
99861
+ * @returns True if successful, false otherwise.
99862
+ */
100223
99863
  async createCollection(collectionName, items) {
100224
99864
  try {
100225
- if (!this.isLoggedIn()) {
99865
+ if (!this.db.isLoggedIn()) {
100226
99866
  console.warn("User not logged in");
100227
99867
  return false;
100228
99868
  }
100229
- if (!this.db.user) {
100230
- console.warn("User node not available");
100231
- return false;
100232
- }
100233
- await this.db.user.get(`collections/${collectionName}`).put(items).then();
99869
+ const user = this.db.getUser();
99870
+ await user.get(`collections/${collectionName}`).put(items).then();
100234
99871
  return true;
100235
99872
  }
100236
99873
  catch (error) {
@@ -100238,18 +99875,21 @@ class SimpleGunAPI {
100238
99875
  return false;
100239
99876
  }
100240
99877
  }
100241
- // Add item to collection - using direct user node
99878
+ /**
99879
+ * Add an item to a user collection.
99880
+ * @param collectionName The name of the collection.
99881
+ * @param itemId The ID of the item to add.
99882
+ * @param item The item data.
99883
+ * @returns True if successful, false otherwise.
99884
+ */
100242
99885
  async addToCollection(collectionName, itemId, item) {
100243
99886
  try {
100244
- if (!this.isLoggedIn()) {
99887
+ if (!this.db.isLoggedIn()) {
100245
99888
  console.warn("User not logged in");
100246
99889
  return false;
100247
99890
  }
100248
- if (!this.db.user) {
100249
- console.warn("User node not available");
100250
- return false;
100251
- }
100252
- await this.db.user
99891
+ const user = this.db.getUser();
99892
+ await user
100253
99893
  .get(`collections/${collectionName}/${itemId}`)
100254
99894
  .put(item)
100255
99895
  .then();
@@ -100260,18 +99900,19 @@ class SimpleGunAPI {
100260
99900
  return false;
100261
99901
  }
100262
99902
  }
100263
- // Get collection - using direct user node
99903
+ /**
99904
+ * Get a user collection.
99905
+ * @param collectionName The name of the collection.
99906
+ * @returns The collection data, or null if not found or not logged in.
99907
+ */
100264
99908
  async getCollection(collectionName) {
100265
99909
  try {
100266
- if (!this.isLoggedIn()) {
99910
+ if (!this.db.isLoggedIn()) {
100267
99911
  console.warn("User not logged in");
100268
99912
  return null;
100269
99913
  }
100270
- if (!this.db.user) {
100271
- console.warn("User node not available");
100272
- return null;
100273
- }
100274
- const collectionData = await this.db.user
99914
+ const user = this.db.getUser();
99915
+ const collectionData = await user
100275
99916
  .get(`collections/${collectionName}`)
100276
99917
  .once()
100277
99918
  .then();
@@ -100282,18 +99923,20 @@ class SimpleGunAPI {
100282
99923
  return null;
100283
99924
  }
100284
99925
  }
100285
- // Remove item from collection - using direct user node
99926
+ /**
99927
+ * Remove an item from a user collection.
99928
+ * @param collectionName The name of the collection.
99929
+ * @param itemId The ID of the item to remove.
99930
+ * @returns True if successful, false otherwise.
99931
+ */
100286
99932
  async removeFromCollection(collectionName, itemId) {
100287
99933
  try {
100288
- if (!this.isLoggedIn()) {
99934
+ if (!this.db.isLoggedIn()) {
100289
99935
  console.warn("User not logged in");
100290
99936
  return false;
100291
99937
  }
100292
- if (!this.db.user) {
100293
- console.warn("User node not available");
100294
- return false;
100295
- }
100296
- await this.db.user
99938
+ const user = this.db.getUser();
99939
+ await user
100297
99940
  .get(`collections/${collectionName}/${itemId}`)
100298
99941
  .put(null)
100299
99942
  .then();