-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move NIP-28 channel helpers to applesauce-channel package
create applesauce-user-status package
- Loading branch information
Showing
22 changed files
with
1,808 additions
and
1,837 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"applesauce-core": minor | ||
--- | ||
|
||
Move NIP-28 channel helpers to applesauce-channel package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# applesauce | ||
# AppleSauce | ||
|
||
AppleSauce is a collection typescript libraries built on top of [nostr-tools](https://github.com/nbd-wtf/nostr-tools) and is used in [noStrudel](https://github.com/hzrd149/nostrudel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 hzrd149 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# applesauce-channel | ||
|
||
Helper methods an queries for [NIP-28](https://github.com/nostr-protocol/nips/blob/master/28.md) Public Channels | ||
|
||
## Install | ||
|
||
```bash | ||
npm install applesauce-core applesauce-channel | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "applesauce-channel", | ||
"version": "0.4.0", | ||
"description": "", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch:build": "tsc --watch > /dev/null", | ||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", | ||
"watch:test": "(trap 'kill 0' SIGINT; pnpm run build -w > /dev/null & pnpm run test --watch)" | ||
}, | ||
"keywords": [ | ||
"nostr" | ||
], | ||
"author": "hzrd149", | ||
"license": "MIT", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./helpers": { | ||
"import": "./dist/helpers/index.js", | ||
"types": "./dist/helpers/index.d.ts" | ||
}, | ||
"./queries": { | ||
"import": "./dist/queries/index.js", | ||
"types": "./dist/queries/index.d.ts" | ||
} | ||
}, | ||
"dependencies": { | ||
"applesauce-core": "^0.4.0", | ||
"nostr-tools": "^2.7.2" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
"@types/jest": "^29.5.13", | ||
"jest": "^29.7.0", | ||
"jest-extended": "^4.0.2" | ||
}, | ||
"jest": { | ||
"roots": [ | ||
"dist" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"jest-extended/all" | ||
] | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./helpers/channel.js"; | ||
export * from "./queries/channel.js"; |
12 changes: 9 additions & 3 deletions
12
packages/core/src/queries/channel.ts → packages/channel/src/queries/channel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"lib": ["ES2022", "DOM"], | ||
|
||
"rootDir": "src", | ||
"outDir": "dist", | ||
|
||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
|
||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"downlevelIteration": true, | ||
"declaration": true, | ||
"strict": true, | ||
|
||
"pretty": true | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,40 @@ | ||
import { Filter, NostrEvent } from "nostr-tools"; | ||
import stringify from "json-stringify-deterministic"; | ||
|
||
import { getReplaceableUID } from "../helpers/event.js"; | ||
import { getEventUID, getReplaceableUID } from "../helpers/event.js"; | ||
import { Query } from "../query-store/index.js"; | ||
|
||
/** Creates a Query that returns a single event or undefined */ | ||
export function SingleEventQuery(uid: string): Query<NostrEvent | undefined> { | ||
return { | ||
key: uid, | ||
run: (events) => events.event(uid), | ||
}; | ||
} | ||
|
||
/** Creates a Query returning the latest version of a replaceable event */ | ||
export function ReplaceableQuery(kind: number, pubkey: string, d?: string): Query<NostrEvent | undefined> { | ||
return { | ||
key: getReplaceableUID(kind, pubkey, d), | ||
run: (events) => events.replaceable(kind, pubkey, d), | ||
}; | ||
} | ||
|
||
/** Creates a Query that returns an array of sorted events matching the filters */ | ||
export function TimelineQuery(filters: Filter | Filter[]): Query<NostrEvent[]> { | ||
return { | ||
key: stringify(filters), | ||
run: (events) => events.timeline(Array.isArray(filters) ? filters : [filters]), | ||
}; | ||
} | ||
|
||
/** Creates a Query that returns a directory of events by their UID */ | ||
export function ReplaceableSetQuery(filters: Filter | Filter[]): Query<Record<string, NostrEvent>> { | ||
return { | ||
key: stringify(filters), | ||
run: (events) => | ||
events | ||
.timeline(Array.isArray(filters) ? filters : [filters]) | ||
.map((events) => events.reduce((dir, event) => ({ ...dir, [getEventUID(event)]: event }), {})), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 hzrd149 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# applesauce-user-status | ||
|
||
Helper methods an queries for [NIP-38](https://github.com/nostr-protocol/nips/blob/master/38.md) User Statuses | ||
|
||
## Install | ||
|
||
```bash | ||
npm install applesauce-core applesauce-user-status | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "applesauce-user-status", | ||
"version": "0.4.0", | ||
"description": "", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"watch:build": "tsc --watch > /dev/null", | ||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", | ||
"watch:test": "(trap 'kill 0' SIGINT; pnpm run build -w > /dev/null & pnpm run test --watch)" | ||
}, | ||
"keywords": [ | ||
"nostr" | ||
], | ||
"author": "hzrd149", | ||
"license": "MIT", | ||
"files": [ | ||
"dist" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
}, | ||
"./helpers": { | ||
"import": "./dist/helpers/index.js", | ||
"types": "./dist/helpers/index.d.ts" | ||
}, | ||
"./queries": { | ||
"import": "./dist/queries/index.js", | ||
"types": "./dist/queries/index.d.ts" | ||
} | ||
}, | ||
"dependencies": { | ||
"applesauce-core": "^0.4.0", | ||
"nostr-tools": "^2.7.2" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
"@types/jest": "^29.5.13", | ||
"jest": "^29.7.0", | ||
"jest-extended": "^4.0.2" | ||
}, | ||
"jest": { | ||
"roots": [ | ||
"dist" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"jest-extended/all" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { NostrEvent } from "nostr-tools"; | ||
import { AddressPointer, EventPointer, ProfilePointer } from "nostr-tools/nip19"; | ||
import { getAddressPointerFromTag, getEventPointerFromTag, getProfilePointerFromTag } from "applesauce-core/helpers"; | ||
|
||
export const UserStatusPointerSymbol = Symbol.for("user-status-pointer"); | ||
declare module "nostr-tools" { | ||
export interface Event { | ||
[UserStatusPointerSymbol]?: UserStatusPointer | null; | ||
} | ||
} | ||
|
||
export type UserStatusPointer = | ||
| { type: "nevent"; data: EventPointer } | ||
| { type: "nprofile"; data: ProfilePointer } | ||
| { type: "naddr"; data: AddressPointer } | ||
| { type: "url"; data: string }; | ||
|
||
function getStatusPointer(status: NostrEvent): UserStatusPointer | null { | ||
const pTag = status.tags.find((t) => t[0] === "p" && t[1]); | ||
if (pTag) return { type: "nprofile", data: getProfilePointerFromTag(pTag) }; | ||
|
||
const eTag = status.tags.find((t) => t[0] === "e" && t[1]); | ||
if (eTag) return { type: "nevent", data: getEventPointerFromTag(eTag) }; | ||
|
||
const aTag = status.tags.find((t) => t[0] === "a" && t[1]); | ||
if (aTag) return { type: "naddr", data: getAddressPointerFromTag(aTag) }; | ||
|
||
const rTag = status.tags.find((t) => t[0] === "r" && t[1]); | ||
if (rTag) return { type: "url", data: rTag[1] }; | ||
|
||
return null; | ||
} | ||
|
||
export function getUserStatusPointer(status: NostrEvent) { | ||
let pointer = status[UserStatusPointerSymbol]; | ||
|
||
if (pointer === undefined) { | ||
pointer = status[UserStatusPointerSymbol] = getStatusPointer(status); | ||
} | ||
|
||
return pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./helpers/user-status.js"; | ||
export * from "./queries/user-status.js"; |
Oops, something went wrong.