Create @ditto/lang, @ditto/policies, @ditto/signers, @ditto/uploaders

This commit is contained in:
Alex Gleason 2025-02-17 17:05:26 -06:00
parent 3ec9ea9c91
commit 5210275d23
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
32 changed files with 59 additions and 40 deletions

View file

@ -5,9 +5,13 @@
"./packages/conf", "./packages/conf",
"./packages/db", "./packages/db",
"./packages/ditto", "./packages/ditto",
"./packages/lang",
"./packages/metrics", "./packages/metrics",
"./packages/policies",
"./packages/ratelimiter", "./packages/ratelimiter",
"./packages/signers",
"./packages/translators", "./packages/translators",
"./packages/uploaders",
"./packages/utils" "./packages/utils"
], ],
"tasks": { "tasks": {

View file

@ -1,32 +1,17 @@
import { NostrFilter } from '@nostrify/nostrify'; import { DittoRoute } from '@ditto/api';
import { z } from 'zod'; import { z } from 'zod';
import { type AppContext, type AppController } from '@/app.ts'; import type { NostrFilter } from '@nostrify/nostrify';
import { getFeedPubkeys } from '@/queries.ts';
import { booleanParamSchema, languageSchema } from '@/schema.ts'; const route = new DittoRoute();
import { hydrateEvents } from '@/storages/hydrate.ts';
import { paginated } from '@/utils/api.ts';
import { getTagSet } from '@/utils/tags.ts';
import { StatusView } from '@/views/mastodon/StatusView.ts';
import { Hono } from '@hono/hono';
const homeQuerySchema = z.object({ const homeQuerySchema = z.object({
exclude_replies: booleanParamSchema.optional(), exclude_replies: booleanParamSchema.optional(),
only_media: booleanParamSchema.optional(), only_media: booleanParamSchema.optional(),
}); });
export interface TimelineRouteOpts { route.get('/home', async (c) => {
} c.req.valid('json');
export class TimelineRoute {
private app: Hono;
constructor(private opts: TimelineRouteOpts) {
this.app = new Hono();
}
}
const homeTimelineController: AppController = async (c) => {
const { user, pagination } = c.var; const { user, pagination } = c.var;
const pubkey = await user!.signer.getPublicKey()!; const pubkey = await user!.signer.getPublicKey()!;
@ -56,7 +41,7 @@ const homeTimelineController: AppController = async (c) => {
} }
return renderStatuses(c, [filter]); return renderStatuses(c, [filter]);
}; });
const publicQuerySchema = z.object({ const publicQuerySchema = z.object({
local: booleanParamSchema.default('false'), local: booleanParamSchema.default('false'),

View file

@ -11,7 +11,7 @@ import { z } from 'zod';
import { DittoPush } from '@/DittoPush.ts'; import { DittoPush } from '@/DittoPush.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts';
import { RelayError } from '@/RelayError.ts'; import { RelayError } from '@/RelayError.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts'; import { AdminSigner } from '../signers/AdminSigner.ts';
import { type EventsDB } from '@/storages/EventsDB.ts'; import { type EventsDB } from '@/storages/EventsDB.ts';
import { hydrateEvents } from '@/storages/hydrate.ts'; import { hydrateEvents } from '@/storages/hydrate.ts';
import { eventAge, Time } from '@/utils.ts'; import { eventAge, Time } from '@/utils.ts';

View file

@ -8,7 +8,7 @@ import { createEvent, paginated, parseBody, updateAdminEvent } from '../../../ut
import { getInstanceMetadata } from '../../../utils/instance.ts'; import { getInstanceMetadata } from '../../../utils/instance.ts';
import { deleteTag } from '../../../utils/tags.ts'; import { deleteTag } from '../../../utils/tags.ts';
import { DittoZapSplits, getZapSplits } from '../../../utils/zap-split.ts'; import { DittoZapSplits, getZapSplits } from '../../../utils/zap-split.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts'; import { AdminSigner } from '../../../signers/AdminSigner.ts';
import { screenshotsSchema } from '@/schemas/nostr.ts'; import { screenshotsSchema } from '@/schemas/nostr.ts';
import { booleanParamSchema, percentageSchema, wsUrlSchema } from '@/schema.ts'; import { booleanParamSchema, percentageSchema, wsUrlSchema } from '@/schema.ts';
import { hydrateEvents } from '@/storages/hydrate.ts'; import { hydrateEvents } from '@/storages/hydrate.ts';

View file

@ -2,7 +2,7 @@ import { z } from 'zod';
import { type AppController } from '@/app.ts'; import { type AppController } from '@/app.ts';
import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts'; import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts'; import { AdminSigner } from '../../../signers/AdminSigner.ts';
import { createAdminEvent, updateAdminEvent, updateUser } from '../../../utils/api.ts'; import { createAdminEvent, updateAdminEvent, updateUser } from '../../../utils/api.ts';
import { lookupPubkey } from '../../../utils/lookup.ts'; import { lookupPubkey } from '../../../utils/lookup.ts';
import { getPleromaConfigs } from '../../../utils/pleroma.ts'; import { getPleromaConfigs } from '../../../utils/pleroma.ts';

View file

@ -11,7 +11,7 @@ import { Kysely } from 'kysely';
import { z } from 'zod'; import { z } from 'zod';
import { type AppController } from '@/app.ts'; import { type AppController } from '@/app.ts';
import { MuteListPolicy } from '@/policies/MuteListPolicy.ts'; import { MuteListPolicy } from '../../../policies/MuteListPolicy.ts';
import { getFeedPubkeys } from '@/queries.ts'; import { getFeedPubkeys } from '@/queries.ts';
import { AdminStore } from '@/storages/AdminStore.ts'; import { AdminStore } from '@/storages/AdminStore.ts';
import { hydrateEvents } from '@/storages/hydrate.ts'; import { hydrateEvents } from '@/storages/hydrate.ts';

View file

@ -6,8 +6,8 @@ import { NostrSigner, NRelay, NSecSigner } from '@nostrify/nostrify';
import { Kysely } from 'kysely'; import { Kysely } from 'kysely';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { ConnectSigner } from '@/signers/ConnectSigner.ts'; import { ConnectSigner } from '../../signers/ConnectSigner.ts';
import { ReadOnlySigner } from '@/signers/ReadOnlySigner.ts'; import { ReadOnlySigner } from '../../signers/ReadOnlySigner.ts';
import { aesDecrypt } from '../../utils/aes.ts'; import { aesDecrypt } from '../../utils/aes.ts';
import { getTokenHash } from '../../utils/auth.ts'; import { getTokenHash } from '../../utils/auth.ts';

View file

@ -2,9 +2,9 @@ import { BlossomUploader, NostrBuildUploader } from '@nostrify/nostrify/uploader
import { safeFetch } from '@soapbox/safe-fetch'; import { safeFetch } from '@soapbox/safe-fetch';
import { AppMiddleware } from '@/app.ts'; import { AppMiddleware } from '@/app.ts';
import { DenoUploader } from '@/uploaders/DenoUploader.ts'; import { DenoUploader } from '../../uploaders/DenoUploader.ts';
import { IPFSUploader } from '@/uploaders/IPFSUploader.ts'; import { IPFSUploader } from '../../uploaders/IPFSUploader.ts';
import { S3Uploader } from '@/uploaders/S3Uploader.ts'; import { S3Uploader } from '../../uploaders/S3Uploader.ts';
/** Set an uploader for the user. */ /** Set an uploader for the user. */
export const uploaderMiddleware: AppMiddleware = async (c, next) => { export const uploaderMiddleware: AppMiddleware = async (c, next) => {

View file

@ -4,7 +4,7 @@ import { NostrFilter, NStore } from '@nostrify/nostrify';
import { logi } from '@soapbox/logi'; import { logi } from '@soapbox/logi';
import { Kysely, sql } from 'kysely'; import { Kysely, sql } from 'kysely';
import { AdminSigner } from '@/signers/AdminSigner.ts'; import { AdminSigner } from '../signers/AdminSigner.ts';
import { errorJson } from '../utils/log.ts'; import { errorJson } from '../utils/log.ts';
import { Time } from '../utils/time.ts'; import { Time } from '../utils/time.ts';

6
packages/lang/deno.json Normal file
View file

@ -0,0 +1,6 @@
{
"name": "@ditto/lang",
"exports": {
".": "./language.ts"
}
}

View file

@ -1,8 +1,8 @@
import { MockRelay } from '@nostrify/nostrify/test'; import { MockRelay } from '@nostrify/nostrify/test';
import { assertEquals } from '@std/assert'; import { assertEquals } from '@std/assert';
import { UserStore } from '@/storages/UserStore.ts';
import { MuteListPolicy } from '@/policies/MuteListPolicy.ts'; import { MuteListPolicy } from './MuteListPolicy.ts';
import userBlack from '~/fixtures/events/kind-0-black.json' with { type: 'json' }; import userBlack from '~/fixtures/events/kind-0-black.json' with { type: 'json' };
import userMe from '~/fixtures/events/event-0-makes-repost-with-quote-repost.json' with { type: 'json' }; import userMe from '~/fixtures/events/event-0-makes-repost-with-quote-repost.json' with { type: 'json' };

View file

@ -1,6 +1,6 @@
import { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/nostrify'; import { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/nostrify';
import { getTagSet } from '../../utils/tags.ts'; import { getTagSet } from '@ditto/utils/tags';
export class MuteListPolicy implements NPolicy { export class MuteListPolicy implements NPolicy {
constructor(private pubkey: string, private store: NStore) {} constructor(private pubkey: string, private store: NStore) {}

View file

@ -0,0 +1,6 @@
{
"name": "@ditto/policies",
"exports": {
".": "./mod.ts"
}
}

1
packages/policies/mod.ts Normal file
View file

@ -0,0 +1 @@
export { MuteListPolicy } from './MuteListPolicy.ts';

View file

@ -0,0 +1,6 @@
{
"name": "@ditto/signers",
"exports": {
".": "./mod.ts"
}
}

3
packages/signers/mod.ts Normal file
View file

@ -0,0 +1,3 @@
export { AdminSigner } from './AdminSigner.ts';
export { ConnectSigner } from './ConnectSigner.ts';
export { ReadOnlySigner } from './ReadOnlySigner.ts';

View file

@ -0,0 +1,6 @@
{
"name": "@ditto/uploaders",
"exports": {
".": "./mod.ts"
}
}

View file

@ -0,0 +1,3 @@
export { DenoUploader } from './DenoUploader.ts';
export { IPFSUploader } from './IPFSUploader.ts';
export { S3Uploader } from './S3Uploader.ts';

View file

@ -19,7 +19,6 @@ type EventStub = TypeFest.SetOptional<EventTemplate, 'content' | 'created_at' |
interface CreateEventOpts { interface CreateEventOpts {
conf: DittoConf; conf: DittoConf;
store: NStore; store: NStore;
pool: NStore;
user: { user: {
signer: NostrSigner; signer: NostrSigner;
}; };

View file

@ -1,6 +1,6 @@
{ {
"name": "@ditto/utils", "name": "@ditto/utils",
"exports": { "exports": {
".": "./mod.ts" "./tags": "./tags.ts"
} }
} }

View file

View file

@ -2,7 +2,7 @@ import { DittoConf } from '@ditto/conf';
import { JsonParseStream } from '@std/json/json-parse-stream'; import { JsonParseStream } from '@std/json/json-parse-stream';
import { TextLineStream } from '@std/streams/text-line-stream'; import { TextLineStream } from '@std/streams/text-line-stream';
import { AdminSigner } from '../packages/ditto/signers/AdminSigner.ts'; import { AdminSigner } from '../packages/signers/AdminSigner.ts';
import { DittoStorages } from '../packages/ditto/DittoStorages.ts'; import { DittoStorages } from '../packages/ditto/DittoStorages.ts';
import { type EventStub } from '../packages/utils/api.ts'; import { type EventStub } from '../packages/utils/api.ts';
import { nostrNow } from '../packages/ditto/utils.ts'; import { nostrNow } from '../packages/ditto/utils.ts';

View file

@ -2,7 +2,7 @@ import { DittoConf } from '@ditto/conf';
import { NSchema } from '@nostrify/nostrify'; import { NSchema } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { AdminSigner } from '../packages/ditto/signers/AdminSigner.ts'; import { AdminSigner } from '../packages/signers/AdminSigner.ts';
import { DittoStorages } from '../packages/ditto/DittoStorages.ts'; import { DittoStorages } from '../packages/ditto/DittoStorages.ts';
import { nostrNow } from '../packages/ditto/utils.ts'; import { nostrNow } from '../packages/ditto/utils.ts';

View file

@ -2,7 +2,7 @@ import { DittoConf } from '@ditto/conf';
import { Command } from 'commander'; import { Command } from 'commander';
import { NostrEvent } from 'nostr-tools'; import { NostrEvent } from 'nostr-tools';
import { AdminSigner } from '../packages/ditto/signers/AdminSigner.ts'; import { AdminSigner } from '../packages/signers/AdminSigner.ts';
import { DittoStorages } from '../packages/ditto/DittoStorages.ts'; import { DittoStorages } from '../packages/ditto/DittoStorages.ts';
import { nostrNow } from '../packages/ditto/utils.ts'; import { nostrNow } from '../packages/ditto/utils.ts';