shogun-core 3.0.3 → 3.0.4

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.
Files changed (95) hide show
  1. package/package.json +1 -1
  2. package/dist/browser/shogun-core.js +0 -92128
  3. package/dist/browser/shogun-core.js.map +0 -1
  4. package/dist/config/simplified-config.js +0 -230
  5. package/dist/core.js +0 -338
  6. package/dist/gundb/crypto.js +0 -268
  7. package/dist/gundb/db.js +0 -1833
  8. package/dist/gundb/derive.js +0 -229
  9. package/dist/gundb/errors.js +0 -66
  10. package/dist/gundb/index.js +0 -6
  11. package/dist/gundb/restricted-put.js +0 -81
  12. package/dist/gundb/rxjs.js +0 -445
  13. package/dist/gundb/simple-api.js +0 -438
  14. package/dist/gundb/types.js +0 -4
  15. package/dist/index.js +0 -16
  16. package/dist/interfaces/common.js +0 -1
  17. package/dist/interfaces/events.js +0 -36
  18. package/dist/interfaces/plugin.js +0 -1
  19. package/dist/interfaces/shogun.js +0 -34
  20. package/dist/managers/AuthManager.js +0 -225
  21. package/dist/managers/CoreInitializer.js +0 -234
  22. package/dist/managers/EventManager.js +0 -67
  23. package/dist/managers/PluginManager.js +0 -296
  24. package/dist/migration-test.js +0 -91
  25. package/dist/plugins/base.js +0 -47
  26. package/dist/plugins/index.js +0 -15
  27. package/dist/plugins/nostr/index.js +0 -4
  28. package/dist/plugins/nostr/nostrConnector.js +0 -413
  29. package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -446
  30. package/dist/plugins/nostr/nostrSigner.js +0 -313
  31. package/dist/plugins/nostr/types.js +0 -1
  32. package/dist/plugins/oauth/index.js +0 -3
  33. package/dist/plugins/oauth/oauthConnector.js +0 -753
  34. package/dist/plugins/oauth/oauthPlugin.js +0 -396
  35. package/dist/plugins/oauth/types.js +0 -1
  36. package/dist/plugins/web3/index.js +0 -4
  37. package/dist/plugins/web3/types.js +0 -1
  38. package/dist/plugins/web3/web3Connector.js +0 -528
  39. package/dist/plugins/web3/web3ConnectorPlugin.js +0 -448
  40. package/dist/plugins/web3/web3Signer.js +0 -308
  41. package/dist/plugins/webauthn/index.js +0 -3
  42. package/dist/plugins/webauthn/types.js +0 -11
  43. package/dist/plugins/webauthn/webauthn.js +0 -478
  44. package/dist/plugins/webauthn/webauthnPlugin.js +0 -398
  45. package/dist/plugins/webauthn/webauthnSigner.js +0 -304
  46. package/dist/storage/storage.js +0 -147
  47. package/dist/types/config/simplified-config.d.ts +0 -114
  48. package/dist/types/core.d.ts +0 -305
  49. package/dist/types/gundb/crypto.d.ts +0 -95
  50. package/dist/types/gundb/db.d.ts +0 -404
  51. package/dist/types/gundb/derive.d.ts +0 -21
  52. package/dist/types/gundb/errors.d.ts +0 -42
  53. package/dist/types/gundb/index.d.ts +0 -3
  54. package/dist/types/gundb/restricted-put.d.ts +0 -15
  55. package/dist/types/gundb/rxjs.d.ts +0 -110
  56. package/dist/types/gundb/simple-api.d.ts +0 -90
  57. package/dist/types/gundb/types.d.ts +0 -264
  58. package/dist/types/index.d.ts +0 -14
  59. package/dist/types/interfaces/common.d.ts +0 -85
  60. package/dist/types/interfaces/events.d.ts +0 -131
  61. package/dist/types/interfaces/plugin.d.ts +0 -162
  62. package/dist/types/interfaces/shogun.d.ts +0 -215
  63. package/dist/types/managers/AuthManager.d.ts +0 -72
  64. package/dist/types/managers/CoreInitializer.d.ts +0 -40
  65. package/dist/types/managers/EventManager.d.ts +0 -49
  66. package/dist/types/managers/PluginManager.d.ts +0 -145
  67. package/dist/types/migration-test.d.ts +0 -16
  68. package/dist/types/plugins/base.d.ts +0 -35
  69. package/dist/types/plugins/index.d.ts +0 -14
  70. package/dist/types/plugins/nostr/index.d.ts +0 -4
  71. package/dist/types/plugins/nostr/nostrConnector.d.ts +0 -119
  72. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +0 -163
  73. package/dist/types/plugins/nostr/nostrSigner.d.ts +0 -105
  74. package/dist/types/plugins/nostr/types.d.ts +0 -122
  75. package/dist/types/plugins/oauth/index.d.ts +0 -3
  76. package/dist/types/plugins/oauth/oauthConnector.d.ts +0 -110
  77. package/dist/types/plugins/oauth/oauthPlugin.d.ts +0 -91
  78. package/dist/types/plugins/oauth/types.d.ts +0 -114
  79. package/dist/types/plugins/web3/index.d.ts +0 -4
  80. package/dist/types/plugins/web3/types.d.ts +0 -107
  81. package/dist/types/plugins/web3/web3Connector.d.ts +0 -129
  82. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +0 -160
  83. package/dist/types/plugins/web3/web3Signer.d.ts +0 -114
  84. package/dist/types/plugins/webauthn/index.d.ts +0 -3
  85. package/dist/types/plugins/webauthn/types.d.ts +0 -162
  86. package/dist/types/plugins/webauthn/webauthn.d.ts +0 -129
  87. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +0 -158
  88. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +0 -91
  89. package/dist/types/storage/storage.d.ts +0 -50
  90. package/dist/types/utils/errorHandler.d.ts +0 -119
  91. package/dist/types/utils/eventEmitter.d.ts +0 -39
  92. package/dist/types/utils/validation.d.ts +0 -27
  93. package/dist/utils/errorHandler.js +0 -241
  94. package/dist/utils/eventEmitter.js +0 -76
  95. package/dist/utils/validation.js +0 -72
@@ -1,445 +0,0 @@
1
- import { Observable } from "rxjs";
2
- import { distinctUntilChanged } from "rxjs/operators";
3
- /**
4
- * RxJS Integration for GunDB
5
- * Provides reactive programming capabilities for GunDB data
6
- */
7
- export class RxJS {
8
- gun;
9
- user;
10
- /**
11
- * Initialize GunRxJS with a GunDB instance
12
- * @param gun - GunDB instance
13
- */
14
- constructor(gun) {
15
- this.gun = gun;
16
- this.user = gun.user();
17
- }
18
- /**
19
- * Get the current user
20
- * @returns The current user
21
- */
22
- getUser() {
23
- return this.user;
24
- }
25
- /**
26
- * Get the current user's public key
27
- * @returns The current user's public key
28
- */
29
- getUserPub() {
30
- return this.user.is?.pub;
31
- }
32
- /**
33
- * Observe a Gun node for changes
34
- * @param path - Path to observe (can be a string or a Gun chain)
35
- * @returns Observable that emits whenever the node changes
36
- */
37
- observe(path) {
38
- return new Observable((subscriber) => {
39
- let node;
40
- if (Array.isArray(path)) {
41
- // Support array paths by chaining get calls
42
- node = this.gun.get(path[0]);
43
- for (let i = 1; i < path.length; i++) {
44
- node = node.get(path[i]);
45
- }
46
- }
47
- else if (typeof path === "string") {
48
- node = this.gun.get(path);
49
- }
50
- else {
51
- node = path;
52
- }
53
- // Subscribe to changes
54
- const unsub = node.on((data, key) => {
55
- if (data === null || data === undefined) {
56
- subscriber.next(null);
57
- return;
58
- }
59
- // Remove Gun metadata before emitting
60
- if (typeof data === "object" && data !== null) {
61
- const cleanData = this.removeGunMeta(data);
62
- subscriber.next(cleanData);
63
- }
64
- else {
65
- subscriber.next(data);
66
- }
67
- });
68
- // Return teardown logic
69
- return () => {
70
- if (unsub && typeof unsub === "function") {
71
- unsub();
72
- }
73
- node.off();
74
- };
75
- }).pipe(distinctUntilChanged((prev, curr) => {
76
- return JSON.stringify(prev) === JSON.stringify(curr);
77
- }));
78
- }
79
- /**
80
- * Match data based on Gun's '.map()' and convert to Observable
81
- * @param path - Path to the collection
82
- * @param matchFn - Optional function to filter results
83
- * @returns Observable array of matched items
84
- */
85
- match(path, matchFn) {
86
- return new Observable((subscriber) => {
87
- if (!path) {
88
- subscriber.next([]);
89
- subscriber.complete();
90
- return;
91
- }
92
- const node = typeof path === "string" ? this.gun.get(path) : path;
93
- const results = {};
94
- const unsub = node.map().on((data, key) => {
95
- // Skip soul key which is Gun's internal reference
96
- if (key === "_" || !data)
97
- return;
98
- if (matchFn && !matchFn(data)) {
99
- // If matchFn is provided and returns false, remove item
100
- if (results[key]) {
101
- delete results[key];
102
- subscriber.next(Object.values(results));
103
- }
104
- return;
105
- }
106
- const cleanData = typeof data === "object" ? this.removeGunMeta(data) : data;
107
- results[key] = cleanData;
108
- subscriber.next(Object.values(results));
109
- });
110
- // Return teardown logic
111
- return () => {
112
- if (unsub && typeof unsub === "function") {
113
- unsub();
114
- }
115
- node.off();
116
- };
117
- });
118
- }
119
- /**
120
- * Put data and return an Observable
121
- * @param path - Path where to put the data
122
- * @param data - Data to put
123
- * @returns Observable that completes when the put is acknowledged
124
- */
125
- put(path, data) {
126
- return new Observable((subscriber) => {
127
- const performPut = (target, value) => {
128
- target.put(value, (ack) => {
129
- if (ack.err) {
130
- subscriber.error(new Error(ack.err));
131
- }
132
- else {
133
- subscriber.next(value);
134
- subscriber.complete();
135
- }
136
- });
137
- };
138
- if (typeof path === "string" || Array.isArray(path)) {
139
- // Path-based put
140
- let node;
141
- if (Array.isArray(path)) {
142
- node = this.gun.get(path[0]);
143
- for (let i = 1; i < path.length; i++)
144
- node = node.get(path[i]);
145
- }
146
- else {
147
- node = this.gun.get(path);
148
- }
149
- performPut(node, data);
150
- }
151
- else {
152
- // Root-level put
153
- performPut(this.gun, path);
154
- }
155
- });
156
- }
157
- /**
158
- * Backward-compatible overload that accepts optional callback like tests expect
159
- */
160
- putCompat(data, callback) {
161
- return new Observable((subscriber) => {
162
- this.gun.put(data, (ack) => {
163
- if (callback)
164
- callback(ack);
165
- if (ack.err) {
166
- subscriber.error(new Error(ack.err));
167
- }
168
- else {
169
- subscriber.next(data);
170
- subscriber.complete();
171
- }
172
- });
173
- });
174
- }
175
- /**
176
- * Set data on a node and return an Observable
177
- * @param path - Path to the collection
178
- * @param data - Data to set
179
- * @returns Observable that completes when the set is acknowledged
180
- */
181
- set(path, data) {
182
- return new Observable((subscriber) => {
183
- const performSet = (target, value) => {
184
- target.set(value, (ack) => {
185
- if (ack.err) {
186
- subscriber.error(new Error(ack.err));
187
- }
188
- else {
189
- subscriber.next(value);
190
- subscriber.complete();
191
- }
192
- });
193
- };
194
- if (typeof path === "string" || Array.isArray(path)) {
195
- let node;
196
- if (Array.isArray(path)) {
197
- node = this.gun.get(path[0]);
198
- for (let i = 1; i < path.length; i++)
199
- node = node.get(path[i]);
200
- }
201
- else {
202
- node = this.gun.get(path);
203
- }
204
- performSet(node, data);
205
- }
206
- else {
207
- performSet(this.gun, path);
208
- }
209
- });
210
- }
211
- setCompat(data, callback) {
212
- return new Observable((subscriber) => {
213
- this.gun.set(data, (ack) => {
214
- if (callback)
215
- callback(ack);
216
- if (ack.err) {
217
- subscriber.error(new Error(ack.err));
218
- }
219
- else {
220
- subscriber.next(data);
221
- subscriber.complete();
222
- }
223
- });
224
- });
225
- }
226
- /**
227
- * Get data once and return as Observable
228
- * @param path - Path to get data from
229
- * @returns Observable that emits the data once
230
- */
231
- once(path) {
232
- let node;
233
- if (typeof path === "string") {
234
- node = this.gun.get(path);
235
- }
236
- else if (path) {
237
- node = path;
238
- }
239
- else {
240
- node = this.gun;
241
- }
242
- return new Observable((subscriber) => {
243
- node.once((data) => {
244
- if (data === undefined || data === null) {
245
- subscriber.next(null);
246
- subscriber.complete();
247
- return;
248
- }
249
- const cleanData = typeof data === "object" ? this.removeGunMeta(data) : data;
250
- subscriber.next(cleanData);
251
- subscriber.complete();
252
- });
253
- });
254
- }
255
- /**
256
- * Compute derived values from gun data
257
- * @param sources - Array of paths or observables to compute from
258
- * @param computeFn - Function that computes a new value from the sources
259
- * @returns Observable of computed values
260
- */
261
- compute(sources, computeFn) {
262
- // Convert all sources to observables
263
- const observables = sources.map((source) => {
264
- if (typeof source === "string") {
265
- return this.observe(source);
266
- }
267
- return source;
268
- });
269
- // Combine the latest values from all sources
270
- return new Observable((subscriber) => {
271
- let values = new Array(sources.length).fill(undefined);
272
- let completed = new Array(sources.length).fill(false);
273
- const subscriptions = observables.map((obs, index) => {
274
- return obs.subscribe({
275
- next: (value) => {
276
- values[index] = value;
277
- // Only compute if we have all values
278
- if (values.every((v) => v !== undefined)) {
279
- try {
280
- const result = computeFn(...values);
281
- subscriber.next(result);
282
- }
283
- catch (error) {
284
- subscriber.error(error);
285
- }
286
- }
287
- },
288
- error: (err) => subscriber.error(err),
289
- complete: () => {
290
- completed[index] = true;
291
- if (completed.every((c) => c)) {
292
- subscriber.complete();
293
- }
294
- },
295
- });
296
- });
297
- // Return teardown logic
298
- return () => {
299
- subscriptions.forEach((sub) => sub.unsubscribe());
300
- };
301
- });
302
- }
303
- /**
304
- * User put data and return an Observable (for authenticated users)
305
- * @param path - Path where to put the data
306
- * @param data - Data to put
307
- * @returns Observable that completes when the put is acknowledged
308
- */
309
- userPut(dataOrPath, maybeData, callback) {
310
- return new Observable((subscriber) => {
311
- const user = this.gun.user();
312
- if (typeof dataOrPath === "string") {
313
- user.get(dataOrPath).put(maybeData, (ack) => {
314
- if (callback)
315
- callback(ack);
316
- if (ack.err) {
317
- subscriber.error(new Error(ack.err));
318
- }
319
- else {
320
- subscriber.next(maybeData);
321
- subscriber.complete();
322
- }
323
- });
324
- }
325
- else {
326
- user.put(dataOrPath, (ack) => {
327
- if (callback)
328
- callback(ack);
329
- if (ack.err) {
330
- subscriber.error(new Error(ack.err));
331
- }
332
- else {
333
- subscriber.next(dataOrPath);
334
- subscriber.complete();
335
- }
336
- });
337
- }
338
- });
339
- }
340
- /**
341
- * User set data and return an Observable (for authenticated users)
342
- * @param dataOrPath - Data to set or path where to set the data
343
- * @param maybeData - Data to set (if first parameter is path)
344
- * @param callback - Optional callback function
345
- * @returns Observable that completes when the set is acknowledged
346
- */
347
- userSet(dataOrPath, maybeData, callback) {
348
- return new Observable((subscriber) => {
349
- const user = this.gun.user();
350
- if (typeof dataOrPath === "string") {
351
- user.get(dataOrPath).set(maybeData, (ack) => {
352
- if (callback)
353
- callback(ack);
354
- if (ack.err) {
355
- subscriber.error(new Error(ack.err));
356
- }
357
- else {
358
- subscriber.next(maybeData);
359
- subscriber.complete();
360
- }
361
- });
362
- }
363
- else {
364
- user.set(dataOrPath, (ack) => {
365
- if (callback)
366
- callback(ack);
367
- if (ack.err) {
368
- subscriber.error(new Error(ack.err));
369
- }
370
- else {
371
- subscriber.next(dataOrPath);
372
- subscriber.complete();
373
- }
374
- });
375
- }
376
- });
377
- }
378
- /**
379
- * User once data and return an Observable (for authenticated users)
380
- * @param path - Optional path to get data from
381
- * @param callback - Optional callback function
382
- * @returns Observable that emits the data once
383
- */
384
- userOnce(path, callback) {
385
- return new Observable((subscriber) => {
386
- const user = this.gun.user();
387
- const target = path ? user.get(path) : user;
388
- target.once((data, ack) => {
389
- if (callback)
390
- callback(ack);
391
- if (ack && ack.err) {
392
- subscriber.error(new Error(ack.err));
393
- }
394
- else {
395
- subscriber.next(data);
396
- subscriber.complete();
397
- }
398
- });
399
- });
400
- }
401
- /**
402
- * Get user data
403
- * @param path - Path to get data from
404
- * @returns Observable that emits the data once
405
- */
406
- userGet(path) {
407
- return this.observe(this.gun.user().get(path));
408
- }
409
- /**
410
- * Observe user data
411
- * @param path - Path to observe in user space
412
- * @returns Observable that emits whenever the user data changes
413
- */
414
- observeUser(path) {
415
- if (path) {
416
- return this.observe(this.gun.user().get(path));
417
- }
418
- return this.observe(this.gun.user().get("~"));
419
- }
420
- /**
421
- * Remove Gun metadata from an object
422
- * @param obj - Object to clean
423
- * @returns Cleaned object without Gun metadata
424
- */
425
- removeGunMeta(obj) {
426
- if (!obj || typeof obj !== "object")
427
- return obj;
428
- // Create a clean copy
429
- const cleanObj = Array.isArray(obj) ? [] : {};
430
- // Copy properties, skipping Gun metadata
431
- Object.keys(obj).forEach((key) => {
432
- // Skip Gun metadata
433
- if (key === "_" || key === "#")
434
- return;
435
- const val = obj[key];
436
- if (val && typeof val === "object") {
437
- cleanObj[key] = this.removeGunMeta(val);
438
- }
439
- else {
440
- cleanObj[key] = val;
441
- }
442
- });
443
- return cleanObj;
444
- }
445
- }