nostr package: delegation #521

Closed
sistemd wants to merge 2 commits from nostr-package-delegation into nostr-package-window-nostr-object
sistemd commented 2023-04-17 19:30:57 +00:00 (Migrated from github.com)

Add delegation. Refactor the event types into classes with an EventCommon base class that contains some common methods. Get rid of RawEvent. The EventCommon type should not be exposed to the user - hopefully this is doable. If this is not doable, then I will refactor it away. Its only purpose is to allow some code to be "easily reused" - it's not necessary for type correctness and it has no utility beyond reusing code.

There are two more things to do to make these classes more ergonomic:

  • Improve the factory methods (e.g. TextNote.create, SetMetadata.create). All parameters should be optional, and the ones that are common to all factory methods can be moved into their own type and reused in every factory method.
  • Improve the event constructors. For example, the userMetadata getter of the SetMetadata event does some validation and throws if this.content is invalid. This pattern repeats in all events. These kinds of validation should instead be done in the event constructor.

Also as finishing touches, much of the docs of this lib will need to be vastly improved in the future. Not sure how close I am to that :-)

Add delegation. Refactor the event types into classes with an `EventCommon` base class that contains some common methods. Get rid of `RawEvent`. The `EventCommon` type should not be exposed to the user - hopefully this is doable. If this is not doable, then I will refactor it away. Its only purpose is to allow some code to be "easily reused" - it's not necessary for type correctness and it has no utility beyond reusing code. There are two more things to do to make these classes more ergonomic: - Improve the factory methods (e.g. `TextNote.create`, `SetMetadata.create`). All parameters should be optional, and the ones that are common to all factory methods can be moved into their own type and reused in every factory method. - Improve the event constructors. For example, the `userMetadata` getter of the `SetMetadata` event does some validation and throws if `this.content` is invalid. This pattern repeats in all events. These kinds of validation should instead be done in the event constructor. Also as finishing touches, much of the docs of this lib will need to be vastly improved in the future. Not sure how close I am to that :-)
v0l (Migrated from github.com) reviewed 2023-04-17 19:30:57 +00:00
cloudflare-pages[bot] commented 2023-04-17 19:35:50 +00:00 (Migrated from github.com)

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 392dcc2
Status:   Deploy successful!
Preview URL: https://8d72961d.snort-social.pages.dev
Branch Preview URL: https://nostr-package-delegation.snort-social.pages.dev

View logs

## Deploying with &nbsp;<a href="https://pages.dev"><img alt="Cloudflare Pages" src="https://user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png" width="16"></a> &nbsp;Cloudflare Pages <table><tr><td><strong>Latest commit:</strong> </td><td> <code>392dcc2</code> </td></tr> <tr><td><strong>Status:</strong></td><td>&nbsp;✅&nbsp; Deploy successful!</td></tr> <tr><td><strong>Preview URL:</strong></td><td> <a href='https://8d72961d.snort-social.pages.dev'>https://8d72961d.snort-social.pages.dev</a> </td></tr> <tr><td><strong>Branch Preview URL:</strong></td><td> <a href='https://nostr-package-delegation.snort-social.pages.dev'>https://nostr-package-delegation.snort-social.pages.dev</a> </td></tr> </table> [View logs](https://dash.cloudflare.com/?to=/:account/pages/view/snort-social/8d72961d-b9e7-4207-adb5-e20d54008970)
v0l commented 2023-04-17 20:15:21 +00:00 (Migrated from github.com)


21:11:30.294 | TS18048: 'window.nostr' is possibly 'undefined'.
-- | --
21:11:30.294 | 188 \|     return await EventExt.decryptData(raw.content, privKey, pubKey);
21:11:30.294 | 189 \|   } else {
21:11:30.295 | > 190 \|     return await barrierNip07(() => window.nostr.nip04.decrypt(pubKey, raw.content));
21:11:30.295 | \|                                     ^^^^^^^^^^^^
21:11:30.295 | 191 \|   }
21:11:30.295 | 192 \| }
21:11:30.295 | 193 \|


``` 21:11:30.294 | TS18048: 'window.nostr' is possibly 'undefined'. -- | -- 21:11:30.294 | 188 \| return await EventExt.decryptData(raw.content, privKey, pubKey); 21:11:30.294 | 189 \| } else { 21:11:30.295 | > 190 \| return await barrierNip07(() => window.nostr.nip04.decrypt(pubKey, raw.content)); 21:11:30.295 | \| ^^^^^^^^^^^^ 21:11:30.295 | 191 \| } 21:11:30.295 | 192 \| } 21:11:30.295 | 193 \| ```
Kieran closed this pull request 2023-05-04 12:57:25 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.