Add global feeds

This commit is contained in:
Jon Staab
2024-06-19 14:50:54 -07:00
parent a61085ff2f
commit 760e0a99b4
4 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@welshman/feeds", "name": "@welshman/feeds",
"version": "0.0.11", "version": "0.0.12",
"author": "hodlbod", "author": "hodlbod",
"license": "MIT", "license": "MIT",
"description": "Utilities for building dynamic nostr feeds.", "description": "Utilities for building dynamic nostr feeds.",
+2
View File
@@ -18,6 +18,7 @@ export class FeedCompiler<E extends TrustedEvent> {
case FeedType.CreatedAt: case FeedType.CreatedAt:
case FeedType.DVM: case FeedType.DVM:
case FeedType.ID: case FeedType.ID:
case FeedType.Global:
case FeedType.Kind: case FeedType.Kind:
case FeedType.List: case FeedType.List:
case FeedType.Label: case FeedType.Label:
@@ -48,6 +49,7 @@ export class FeedCompiler<E extends TrustedEvent> {
case FeedType.Search: return this._compileSearches(getFeedArgs(feed)) case FeedType.Search: return this._compileSearches(getFeedArgs(feed))
case FeedType.WOT: return this._compileWot(getFeedArgs(feed)) case FeedType.WOT: return this._compileWot(getFeedArgs(feed))
case FeedType.Relay: return [{relays: getFeedArgs(feed)}] case FeedType.Relay: return [{relays: getFeedArgs(feed)}]
case FeedType.Global: return [{filters: [{}]}]
case FeedType.Tag: { case FeedType.Tag: {
const [key, ...value] = getFeedArgs(feed) const [key, ...value] = getFeedArgs(feed)
+3
View File
@@ -8,6 +8,7 @@ export enum FeedType {
Difference = "difference", Difference = "difference",
ID = "id", ID = "id",
Intersection = "intersection", Intersection = "intersection",
Global = "global",
Kind = "kind", Kind = "kind",
List = "list", List = "list",
Label = "label", Label = "label",
@@ -73,6 +74,7 @@ export type DVMFeed = [type: FeedType.DVM, ...items: DVMItem[]]
export type DifferenceFeed = [type: FeedType.Difference, ...feeds: Feed[]] export type DifferenceFeed = [type: FeedType.Difference, ...feeds: Feed[]]
export type IDFeed = [type: FeedType.ID, ...ids: string[]] export type IDFeed = [type: FeedType.ID, ...ids: string[]]
export type IntersectionFeed = [type: FeedType.Intersection, ...feeds: Feed[]] export type IntersectionFeed = [type: FeedType.Intersection, ...feeds: Feed[]]
export type GlobalFeed = [type: FeedType.Global, ...feeds: Feed[]]
export type KindFeed = [type: FeedType.Kind, ...kinds: number[]] export type KindFeed = [type: FeedType.Kind, ...kinds: number[]]
export type ListFeed = [type: FeedType.List, ...items: ListItem[]] export type ListFeed = [type: FeedType.List, ...items: ListItem[]]
export type LabelFeed = [type: FeedType.Label, ...items: LabelItem[]] export type LabelFeed = [type: FeedType.Label, ...items: LabelItem[]]
@@ -91,6 +93,7 @@ export type Feed =
DifferenceFeed | DifferenceFeed |
IDFeed | IDFeed |
IntersectionFeed | IntersectionFeed |
GlobalFeed |
KindFeed | KindFeed |
ListFeed | ListFeed |
LabelFeed | LabelFeed |
+5
View File
@@ -11,6 +11,7 @@ import {
DifferenceFeed, DifferenceFeed,
IDFeed, IDFeed,
IntersectionFeed, IntersectionFeed,
GlobalFeed,
KindFeed, KindFeed,
ListFeed, ListFeed,
LabelFeed, LabelFeed,
@@ -36,6 +37,7 @@ export const makeDVMFeed = (...items: DVMItem[]): DVMFeed
export const makeDifferenceFeed = (...feeds: Feed[]): DifferenceFeed => [FeedType.Difference, ...feeds] export const makeDifferenceFeed = (...feeds: Feed[]): DifferenceFeed => [FeedType.Difference, ...feeds]
export const makeIDFeed = (...ids: string[]): IDFeed => [FeedType.ID, ...ids] export const makeIDFeed = (...ids: string[]): IDFeed => [FeedType.ID, ...ids]
export const makeIntersectionFeed = (...feeds: Feed[]): IntersectionFeed => [FeedType.Intersection, ...feeds] export const makeIntersectionFeed = (...feeds: Feed[]): IntersectionFeed => [FeedType.Intersection, ...feeds]
export const makeGlobalFeed = (): GlobalFeed => [FeedType.Global]
export const makeKindFeed = (...kinds: number[]): KindFeed => [FeedType.Kind, ...kinds] export const makeKindFeed = (...kinds: number[]): KindFeed => [FeedType.Kind, ...kinds]
export const makeListFeed = (...items: ListItem[]): ListFeed => [FeedType.List, ...items] export const makeListFeed = (...items: ListItem[]): ListFeed => [FeedType.List, ...items]
export const makeLabelFeed = (...items: LabelItem[]): LabelFeed => [FeedType.Label, ...items] export const makeLabelFeed = (...items: LabelItem[]): LabelFeed => [FeedType.Label, ...items]
@@ -53,6 +55,7 @@ export const isDVMFeed = (feed: Feed): feed is DVMFeed
export const isDifferenceFeed = (feed: Feed): feed is DifferenceFeed => feed[0] === FeedType.Difference export const isDifferenceFeed = (feed: Feed): feed is DifferenceFeed => feed[0] === FeedType.Difference
export const isIDFeed = (feed: Feed): feed is IDFeed => feed[0] === FeedType.ID export const isIDFeed = (feed: Feed): feed is IDFeed => feed[0] === FeedType.ID
export const isIntersectionFeed = (feed: Feed): feed is IntersectionFeed => feed[0] === FeedType.Intersection export const isIntersectionFeed = (feed: Feed): feed is IntersectionFeed => feed[0] === FeedType.Intersection
export const isGlobalFeed = (feed: Feed): feed is GlobalFeed => feed[0] === FeedType.Global
export const isKindFeed = (feed: Feed): feed is KindFeed => feed[0] === FeedType.Kind export const isKindFeed = (feed: Feed): feed is KindFeed => feed[0] === FeedType.Kind
export const isListFeed = (feed: Feed): feed is ListFeed => feed[0] === FeedType.List export const isListFeed = (feed: Feed): feed is ListFeed => feed[0] === FeedType.List
export const isLabelFeed = (feed: Feed): feed is LabelFeed => feed[0] === FeedType.Label export const isLabelFeed = (feed: Feed): feed is LabelFeed => feed[0] === FeedType.Label
@@ -73,6 +76,7 @@ export function getFeedArgs(feed: WOTFeed): WOTItem[]
export function getFeedArgs(feed: ScopeFeed): Scope[] export function getFeedArgs(feed: ScopeFeed): Scope[]
export function getFeedArgs(feed: KindFeed): number[] export function getFeedArgs(feed: KindFeed): number[]
export function getFeedArgs(feed: TagFeed): [string, ...string[]] export function getFeedArgs(feed: TagFeed): [string, ...string[]]
export function getFeedArgs(feed: GlobalFeed): []
export function getFeedArgs(feed: Feed) { export function getFeedArgs(feed: Feed) {
switch (feed[0]) { switch (feed[0]) {
case FeedType.Intersection: return feed.slice(1) as Feed[] case FeedType.Intersection: return feed.slice(1) as Feed[]
@@ -91,6 +95,7 @@ export function getFeedArgs(feed: Feed) {
case FeedType.WOT: return feed.slice(1) as WOTItem[] case FeedType.WOT: return feed.slice(1) as WOTItem[]
case FeedType.Scope: return feed.slice(1) as Scope[] case FeedType.Scope: return feed.slice(1) as Scope[]
case FeedType.Kind: return feed.slice(1) as number[] case FeedType.Kind: return feed.slice(1) as number[]
case FeedType.Global: return feed.slice(1) as never[]
} }
} }