shogun-core 3.0.13 → 3.0.14

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
@@ -217,7 +217,11 @@ const settings = await shogun.api.getSettings();
217
217
  await shogun.api.savePreferences({ theme: 'dark', fontSize: 14 });
218
218
  const preferences = await shogun.api.getPreferences();
219
219
 
220
- // Collections (for structured data)
220
+ // Collections (recommended for structured data)
221
+ // Note: Array functions (putUserArray, getUserArray, etc.) have been removed due to GunDB compatibility issues
222
+ // Use collections or direct GunDB operations instead:
223
+
224
+ // Option 1: Collections (recommended for most use cases)
221
225
  await shogun.api.createCollection('todos', {
222
226
  '1': { text: 'Learn Shogun Core', done: false },
223
227
  '2': { text: 'Build dApp', done: false }
@@ -231,6 +235,12 @@ await shogun.api.addToCollection('todos', '3', {
231
235
  const todos = await shogun.api.getCollection('todos');
232
236
  await shogun.api.removeFromCollection('todos', '2');
233
237
 
238
+ // Option 2: Direct GunDB operations for complex nested data
239
+ await shogun.api.node('users').get('alice').get('todos').get('1').put({
240
+ text: 'Learn Shogun Core',
241
+ done: false
242
+ });
243
+
234
244
  // Utility methods
235
245
  const currentUser = shogun.api.getCurrentUser();
236
246
  const userExists = await shogun.api.userExists('username');
@@ -777,6 +787,16 @@ You can also use Shogun Core directly in the browser by including it from a CDN.
777
787
  - `getCollection(name: string): Promise<Record<string, unknown> | null>` - Get collection
778
788
  - `removeFromCollection(name: string, itemId: string): Promise<boolean>` - Remove item from collection
779
789
 
790
+ #### Utility Functions
791
+ - `arrayToIndexedObject<T>(arr: T[]): Record<string, T>` - Convert array to indexed object (helper)
792
+ - `indexedObjectToArray<T>(indexedObj: Record<string, T>): T[]` - Convert indexed object to array (helper)
793
+
794
+ #### ⚠️ **REMOVED FUNCTIONS**
795
+ The following array functions have been **REMOVED** due to GunDB compatibility issues:
796
+ - `putUserArray()`, `getUserArray()`, `addToUserArray()`, `removeFromUserArray()`, `updateInUserArray()`
797
+
798
+ **Use collections or direct GunDB operations instead** (see examples above).
799
+
780
800
  ### Advanced API Methods
781
801
 
782
802
  #### Core Authentication
@@ -89993,147 +89993,6 @@ class SimpleGunAPI {
89993
89993
  indexedObjectToArray(indexedObj) {
89994
89994
  return this.getArrayFromIndexedObject(indexedObj);
89995
89995
  }
89996
- // Save array as indexed object in user space
89997
- async putUserArray(path, arr) {
89998
- try {
89999
- if (!this.isLoggedIn()) {
90000
- console.warn("User not logged in");
90001
- return false;
90002
- }
90003
- const indexedObject = this.getIndexedObjectFromArray(arr);
90004
- return await this.putUserData(path, indexedObject);
90005
- }
90006
- catch (error) {
90007
- console.warn(`Failed to put user array to ${path}:`, error);
90008
- return false;
90009
- }
90010
- }
90011
- // Get array from indexed object in user space
90012
- async getUserArray(path) {
90013
- try {
90014
- if (!this.isLoggedIn()) {
90015
- console.warn("User not logged in");
90016
- return [];
90017
- }
90018
- const indexedObject = await this.getUserData(path);
90019
- return this.getArrayFromIndexedObject(indexedObject);
90020
- }
90021
- catch (error) {
90022
- console.warn(`Failed to get user array from ${path}:`, error);
90023
- return [];
90024
- }
90025
- }
90026
- // Add item to user array collection
90027
- async addToUserArray(path, item) {
90028
- try {
90029
- if (!this.isLoggedIn()) {
90030
- console.warn("User not logged in");
90031
- return false;
90032
- }
90033
- // Validate item before adding
90034
- if (!item || typeof item !== "object" || !item.id) {
90035
- console.warn("Invalid item: must be an object with an id property");
90036
- return false;
90037
- }
90038
- const currentArray = await this.getUserArray(path);
90039
- const newArray = [...currentArray, item];
90040
- return await this.putUserArray(path, newArray);
90041
- }
90042
- catch (error) {
90043
- console.warn(`Failed to add item to user array ${path}:`, error);
90044
- return false;
90045
- }
90046
- }
90047
- // Remove item from user array collection
90048
- async removeFromUserArray(path, itemId) {
90049
- try {
90050
- if (!this.isLoggedIn()) {
90051
- console.warn("User not logged in");
90052
- return false;
90053
- }
90054
- const currentArray = await this.getUserArray(path);
90055
- const newArray = currentArray.filter((item) => item.id !== itemId);
90056
- return await this.putUserArray(path, newArray);
90057
- }
90058
- catch (error) {
90059
- console.warn(`Failed to remove item from user array ${path}:`, error);
90060
- return false;
90061
- }
90062
- }
90063
- // Update item in user array collection
90064
- async updateInUserArray(path, itemId, updates) {
90065
- try {
90066
- if (!this.isLoggedIn()) {
90067
- console.warn("User not logged in");
90068
- return false;
90069
- }
90070
- const currentArray = await this.getUserArray(path);
90071
- const newArray = currentArray.map((item) => item.id === itemId ? { ...item, ...updates } : item);
90072
- return await this.putUserArray(path, newArray);
90073
- }
90074
- catch (error) {
90075
- console.warn(`Failed to update item in user array ${path}:`, error);
90076
- return false;
90077
- }
90078
- }
90079
- // Save array as indexed object in global space
90080
- async putArray(path, arr) {
90081
- try {
90082
- const indexedObject = this.getIndexedObjectFromArray(arr);
90083
- return await this.put(path, indexedObject);
90084
- }
90085
- catch (error) {
90086
- console.warn(`Failed to put array to ${path}:`, error);
90087
- return false;
90088
- }
90089
- }
90090
- // Get array from indexed object in global space
90091
- async getArray(path) {
90092
- try {
90093
- const indexedObject = await this.get(path);
90094
- return this.getArrayFromIndexedObject(indexedObject);
90095
- }
90096
- catch (error) {
90097
- console.warn(`Failed to get array from ${path}:`, error);
90098
- return [];
90099
- }
90100
- }
90101
- // Add item to global array collection
90102
- async addToArray(path, item) {
90103
- try {
90104
- const currentArray = await this.getArray(path);
90105
- const newArray = [...currentArray, item];
90106
- return await this.putArray(path, newArray);
90107
- }
90108
- catch (error) {
90109
- console.warn(`Failed to add item to array ${path}:`, error);
90110
- return false;
90111
- }
90112
- }
90113
- // Remove item from global array collection
90114
- async removeFromArray(path, itemId) {
90115
- try {
90116
- const currentArray = await this.getArray(path);
90117
- const newArray = currentArray.filter((item) => item.id !== itemId);
90118
- return await this.putArray(path, newArray);
90119
- }
90120
- catch (error) {
90121
- console.warn(`Failed to remove item from array ${path}:`, error);
90122
- return false;
90123
- }
90124
- }
90125
- // Update item in global array collection
90126
- async updateInArray(path, itemId, updates) {
90127
- try {
90128
- const currentArray = await this.getArray(path);
90129
- const newArray = currentArray.map((item) => item.id === itemId ? { ...item, ...updates } : item);
90130
- return await this.putArray(path, newArray);
90131
- }
90132
- catch (error) {
90133
- console.warn(`Failed to update item in array ${path}:`, error);
90134
- return false;
90135
- }
90136
- }
90137
89996
  /**
90138
89997
  * Path utilities
90139
89998
  */