Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
BlowaterNostr committed Apr 2, 2024
1 parent a0a82f9 commit b01f863
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
3 changes: 1 addition & 2 deletions main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Policy } from "./resolvers/policy.ts";
import { func_ResolvePolicyByKind } from "./resolvers/policy.ts";
import { func_GetEventsByKinds, func_WriteEvent } from "./resolvers/event.ts";
import { EventStore, func_GetEventsByIDs } from "./resolvers/event.ts";
import { GetEventsByKinds } from "./resolvers/event.ts";
import { NostrEvent, NostrKind, parseJSON, PublicKey, verifyEvent } from "./_libs.ts";
import { PolicyStore } from "./resolvers/policy.ts";
import { Policies } from "./resolvers/policy.ts";
Expand Down Expand Up @@ -81,7 +80,7 @@ export async function run(args: {
resolvePolicyByKind: policyStore.resolvePolicyByKind,
write_event: eventStore.write_event.bind(eventStore),
get_events_by_IDs: eventStore.get_events_by_IDs.bind(eventStore),
get_events_by_kinds: GetEventsByKinds(args.kv),
get_events_by_kinds: eventStore.get_events_by_kinds.bind(eventStore),
get_events_by_authors: eventStore.get_events_by_authors.bind(eventStore),
policyStore,
kv: args.kv,
Expand Down
31 changes: 17 additions & 14 deletions resolvers/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,10 @@ export type interface_GetEventsByIDs = {
get_events_by_IDs: func_GetEventsByIDs;
};

export type func_GetEventsByKinds = (kinds: NostrKind[]) => AsyncIterable<NostrEvent>;
export const GetEventsByKinds = (kv: Deno.Kv): func_GetEventsByKinds =>
async function* x(kinds: NostrKind[]) {
for (const kind of kinds) {
const list = kv.list<NostrEvent>({ prefix: ["event", kind] });
for await (const entry of list) {
console.log(entry);
if (entry.value) {
yield entry.value;
}
}
}
};
export type func_GetEventsByKinds = (kinds: Set<NostrKind>) => AsyncIterable<NostrEvent>;
export type interface_GetEventsByKinds = {
get_events_by_kinds: func_GetEventsByKinds;
};

export type func_GetEventsByAuthors = (authors: Set<string>) => AsyncIterable<NostrEvent>;
export type interface_GetEventsByAuthors = {
Expand All @@ -42,7 +33,11 @@ export type interface_WriteEvent = {
};

export class EventStore
implements interface_GetEventsByAuthors, interface_WriteEvent, interface_GetEventsByIDs {
implements
interface_GetEventsByAuthors,
interface_WriteEvent,
interface_GetEventsByIDs,
interface_GetEventsByKinds {
private constructor(
private events: Map<string, NostrEvent>,
private kv: Deno.Kv,
Expand Down Expand Up @@ -74,6 +69,14 @@ export class EventStore
}
}

async *get_events_by_kinds(kinds: Set<NostrKind>) {
for (const event of this.events.values()) {
if (kinds.has(event.kind)) {
yield event;
}
}
}

async write_event(event: NostrEvent) {
console.log("write_event", event);
const result = await this.kv.atomic()
Expand Down
2 changes: 1 addition & 1 deletion ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async function handle_filter(args: {
event_candidates.delete(key);
}
} else {
const events = get_events_by_kinds(filter.kinds);
const events = get_events_by_kinds(new Set(filter.kinds));
for await (const event of events) {
console.log(event);
event_candidates.set(event.id, event);
Expand Down

2 comments on commit b01f863

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on b01f863 Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

ISOLATE_INTERNAL_FAILURE

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on b01f863 Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

ISOLATE_INTERNAL_FAILURE

Please sign in to comment.