@welshman/app 0.0.33 → 0.0.34

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 (2) hide show
  1. package/README.md +70 -0
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
1
  # @welshman/store [![version](https://badgen.net/npm/v/@welshman/store)](https://npmjs.com/package/@welshman/store)
2
2
 
3
3
  Utilities for dealing with svelte stores when using welshman.
4
+
5
+ ```typescript
6
+ import {ctx, setContext} from '@welshman/lib'
7
+ import {getNip07} from '@welshman/signer'
8
+ import {throttled} from '@welshman/store'
9
+ import {createEvent, NOTE} from '@welshman/util'
10
+ import {
11
+ getDefaultNetContext,
12
+ getDefaultAppContext,
13
+ signer,
14
+ pubkey,
15
+ publishThunk,
16
+ load,
17
+ initStorage,
18
+ storageAdapters,
19
+ freshness,
20
+ plaintext,
21
+ repository,
22
+ tracker,
23
+ } from '@welshman/app'
24
+
25
+ // Set up app config
26
+ setContext({
27
+ net: getDefaultNetContext(),
28
+ app: getDefaultAppContext(),
29
+ })
30
+
31
+ // Log in via NIP 07
32
+ addSession({method: 'nip07', pubkey: await getNip07().getPubkey()})
33
+
34
+ // Signer is ready to go
35
+ const event = signer.get().encrypt(/* ... */)
36
+
37
+ // This will fetch the user's profile automatically, and return an observable that updates
38
+ // automatically. Several different stores exist that are ready to go, including handles,
39
+ // zappers, relaySelections, relays, follows, mutes.
40
+ const profile = deriveProfile(pubkey.get())
41
+
42
+ // A global router helps make intelligent relay selections
43
+ const router = ctx.app.router
44
+
45
+ // Publish is done using thunks, which optimistically publish to the local database, deferring
46
+ // signing and publishing for instant user feedback. Progress is reported as relays accept/reject the event
47
+ const thunk = publishThunk({
48
+ relays: router.FromUser().getUrls(),
49
+ event: createEvent(NOTE, {content: "hi"}),
50
+ delay: 3000,
51
+ })
52
+
53
+ // Thunks can be aborted until after `delay`, allowing for soft-undo
54
+ thunk.controller.abort()
55
+
56
+ // Subscriptions automatically infer relays using `router` if not provided. If the request can be cached,
57
+ // results from the local repository are returned immediately. `subscribe` and `load` are both available
58
+ const events = await load({filters: [{kinds: [NOTE]}])
59
+
60
+ // Some commands are included
61
+ const thunk = follow('97c70a44366a6535c145b333f973ea86dfdc2d7a99da618c40c64705ad98e322')
62
+
63
+ // Stores can be easily synchronized with indexeddb. Freshness keeps track of how stale the caches are,
64
+ // plaintext maps encrypted events to their decrypted content, repository and tracker hold events and
65
+ // event/relay mappings, respectively.
66
+ const ready = initStorage("my-db", 1, {
67
+ relays: {keyPath: "url", store: throttled(3000, relays)},
68
+ handles: {keyPath: "nip05", store: throttled(3000, handles)},
69
+ freshness: storageAdapters.fromObjectStore(freshness, {throttle: 3000}),
70
+ plaintext: storageAdapters.fromObjectStore(plaintext, {throttle: 3000}),
71
+ events: storageAdapters.fromRepositoryAndTracker(repository, tracker, {throttle: 3000}),
72
+ })
73
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@welshman/app",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "author": "hodlbod",
5
5
  "license": "MIT",
6
6
  "description": "A collection of svelte stores for use in building nostr client applications.",
@@ -34,11 +34,11 @@
34
34
  "@types/throttle-debounce": "^5.0.2",
35
35
  "@welshman/dvm": "~0.0.11",
36
36
  "@welshman/feeds": "~0.0.26",
37
- "@welshman/lib": "~0.0.29",
37
+ "@welshman/lib": "~0.0.33",
38
38
  "@welshman/net": "~0.0.41",
39
39
  "@welshman/signer": "~0.0.16",
40
40
  "@welshman/store": "~0.0.13",
41
- "@welshman/util": "~0.0.48",
41
+ "@welshman/util": "~0.0.50",
42
42
  "fuse.js": "^7.0.0",
43
43
  "idb": "^8.0.0",
44
44
  "svelte": "^4.2.18",