Fix DittoEnv type check

This commit is contained in:
Alex Gleason 2025-02-22 21:52:26 -06:00
parent f1cb8c778a
commit 237f6e55ad
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 11 additions and 7 deletions

View file

@ -78,7 +78,6 @@ route.put('/wallet', userMiddleware({ enc: 'nip44' }), async (c) => {
await createEvent({
kind: 17375,
content: encryptedWalletContentTags,
// @ts-ignore kill me
}, c);
// Nutzap information
@ -89,7 +88,6 @@ route.put('/wallet', userMiddleware({ enc: 'nip44' }), async (c) => {
['relay', conf.relay], // TODO: add more relays once things get more stable
['pubkey', p2pk],
],
// @ts-ignore kill me
}, c);
// TODO: hydrate wallet and add a 'balance' field when a 'renderWallet' view function is created

View file

@ -1,3 +1,5 @@
import { User } from '@ditto/mastoapi/middleware';
import { DittoEnv } from '@ditto/mastoapi/router';
import { HTTPException } from '@hono/hono/http-exception';
import { NostrEvent, NostrFilter } from '@nostrify/nostrify';
import { EventTemplate } from 'nostr-tools';
@ -6,12 +8,16 @@ import * as TypeFest from 'type-fest';
import { type AppContext } from '@/app.ts';
import { nostrNow } from '@/utils.ts';
import { parseFormData } from '@/utils/formdata.ts';
import { Context } from '@hono/hono';
/** EventTemplate with defaults. */
type EventStub = TypeFest.SetOptional<EventTemplate, 'content' | 'created_at' | 'tags'>;
/** Publish an event through the pipeline. */
async function createEvent(t: EventStub, c: AppContext): Promise<NostrEvent> {
async function createEvent<E extends (DittoEnv & { Variables: { user?: User } })>(
t: EventStub,
c: Context<E>,
): Promise<NostrEvent> {
const { user, relay, signal } = c.var;
if (!user) {

View file

@ -7,8 +7,8 @@ import type { NostrEvent } from '@nostrify/nostrify';
type HeaderRecord = Record<string, string | string[]>;
/** Return results with pagination headers. Assumes chronological sorting of events. */
export function paginated(
c: Context<DittoEnv>,
export function paginated<E extends DittoEnv>(
c: Context<E>,
events: NostrEvent[],
body: object | unknown[],
headers: HeaderRecord = {},
@ -28,8 +28,8 @@ export function paginated(
}
/** paginate a list of tags. */
export function paginatedList(
c: Context<DittoEnv>,
export function paginatedList<E extends DittoEnv>(
c: Context<E>,
params: { offset: number; limit: number },
body: object | unknown[],
headers: HeaderRecord = {},