diff --git a/deno.json b/deno.json index ce334b87..d31490e2 100644 --- a/deno.json +++ b/deno.json @@ -47,8 +47,8 @@ "@lambdalisue/async": "jsr:@lambdalisue/async@^2.1.1", "@negrel/webpush": "jsr:@negrel/webpush@^0.3.0", "@noble/secp256k1": "npm:@noble/secp256k1@^2.0.0", - "@nostrify/db": "jsr:@nostrify/db@^0.37.3", - "@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.38.0", + "@nostrify/db": "jsr:@nostrify/db@^0.38.0", + "@nostrify/nostrify": "jsr:@nostrify/nostrify@^0.38.1", "@nostrify/policies": "jsr:@nostrify/policies@^0.36.1", "@nostrify/types": "jsr:@nostrify/types@^0.36.0", "@scure/base": "npm:@scure/base@^1.1.6", @@ -73,7 +73,7 @@ "fast-stable-stringify": "npm:fast-stable-stringify@^1.0.0", "formdata-helper": "npm:formdata-helper@^0.3.0", "hono-rate-limiter": "npm:hono-rate-limiter@^0.3.0", - "iso-639-1": "npm:iso-639-1@2.1.15", + "iso-639-1": "npm:iso-639-1@^3.1.5", "isomorphic-dompurify": "npm:isomorphic-dompurify@^2.16.0", "kysely": "npm:kysely@^0.27.4", "kysely-postgres-js": "npm:kysely-postgres-js@2.0.0", diff --git a/deno.lock b/deno.lock index 9ff5ee11..9896965a 100644 --- a/deno.lock +++ b/deno.lock @@ -31,14 +31,15 @@ "jsr:@lambdalisue/async@^2.1.1": "2.1.1", "jsr:@negrel/http-ece@0.6.0": "0.6.0", "jsr:@negrel/webpush@0.3": "0.3.0", - "jsr:@nostrify/db@~0.37.3": "0.37.3", + "jsr:@nostrify/db@0.38": "0.38.0", "jsr:@nostrify/nostrify@0.31": "0.31.0", "jsr:@nostrify/nostrify@0.32": "0.32.0", "jsr:@nostrify/nostrify@0.36": "0.36.2", - "jsr:@nostrify/nostrify@0.38": "0.38.0", + "jsr:@nostrify/nostrify@0.38": "0.38.1", "jsr:@nostrify/nostrify@~0.22.1": "0.22.5", "jsr:@nostrify/nostrify@~0.22.4": "0.22.4", "jsr:@nostrify/nostrify@~0.22.5": "0.22.5", + "jsr:@nostrify/nostrify@~0.38.1": "0.38.1", "jsr:@nostrify/policies@0.33": "0.33.0", "jsr:@nostrify/policies@0.33.1": "0.33.1", "jsr:@nostrify/policies@0.34": "0.34.0", @@ -102,7 +103,7 @@ "npm:fast-stable-stringify@1": "1.0.0", "npm:formdata-helper@0.3": "0.3.0", "npm:hono-rate-limiter@0.3": "0.3.0_hono@4.2.5", - "npm:iso-639-1@2.1.15": "2.1.15", + "npm:iso-639-1@^3.1.5": "3.1.5", "npm:isomorphic-dompurify@^2.16.0": "2.16.0", "npm:kysely-postgres-js@2.0.0": "2.0.0_kysely@0.27.3_postgres@3.4.4", "npm:kysely@~0.27.2": "0.27.4", @@ -357,10 +358,10 @@ "jsr:@std/path@0.224.0" ] }, - "@nostrify/db@0.37.3": { - "integrity": "fe7cacd67bb817f10fb44587e832cfb042a3a0d32db29b24a487b7d006438623", + "@nostrify/db@0.38.0": { + "integrity": "44118756b95f747779839f0e578a5e1dbca164ec44edb8885bd1c99840775e8a", "dependencies": [ - "jsr:@nostrify/nostrify@0.38", + "jsr:@nostrify/nostrify@~0.38.1", "jsr:@nostrify/types@0.36", "npm:kysely@~0.27.3", "npm:nostr-tools@^2.10.4" @@ -479,6 +480,21 @@ "npm:zod" ] }, + "@nostrify/nostrify@0.38.1": { + "integrity": "087d1be0d5c46420e6040b07c8cfb1a3ecb9808f23de54d22dd64d3eed001bce", + "dependencies": [ + "jsr:@nostrify/types@0.36", + "jsr:@std/crypto", + "jsr:@std/encoding@~0.224.1", + "npm:@scure/base", + "npm:@scure/bip32", + "npm:@scure/bip39", + "npm:lru-cache@^10.2.0", + "npm:nostr-tools@^2.10.4", + "npm:websocket-ts", + "npm:zod" + ] + }, "@nostrify/policies@0.33.0": { "integrity": "c946b06d0527298b4d7c9819d142a10f522ba09eee76c37525aa4acfc5d87aee", "dependencies": [ @@ -1271,8 +1287,8 @@ "isexe@2.0.0": { "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, - "iso-639-1@2.1.15": { - "integrity": "sha512-7c7mBznZu2ktfvyT582E2msM+Udc1EjOyhVRE/0ZsjD9LBtWSm23h3PtiRh2a35XoUsTQQjJXaJzuLjXsOdFDg==" + "iso-639-1@3.1.5": { + "integrity": "sha512-gXkz5+KN7HrG0Q5UGqSMO2qB9AsbEeyLP54kF1YrMsIxmu+g4BdB7rflReZTSTZGpfj8wywu6pfPBCylPIzGQA==" }, "isomorphic-dompurify@2.16.0": { "integrity": "sha512-cXhX2owp8rPxafCr0ywqy2CGI/4ceLNgWkWBEvUz64KTbtg3oRL2ZRqq/zW0pzt4YtDjkHLbwcp/lozpKzAQjg==", @@ -2416,8 +2432,8 @@ "jsr:@hono/hono@^4.4.6", "jsr:@lambdalisue/async@^2.1.1", "jsr:@negrel/webpush@0.3", - "jsr:@nostrify/db@~0.37.3", - "jsr:@nostrify/nostrify@0.38", + "jsr:@nostrify/db@0.38", + "jsr:@nostrify/nostrify@~0.38.1", "jsr:@nostrify/policies@~0.36.1", "jsr:@nostrify/types@0.36", "jsr:@soapbox/kysely-pglite@1", @@ -2444,7 +2460,7 @@ "npm:fast-stable-stringify@1", "npm:formdata-helper@0.3", "npm:hono-rate-limiter@0.3", - "npm:iso-639-1@2.1.15", + "npm:iso-639-1@^3.1.5", "npm:isomorphic-dompurify@^2.16.0", "npm:kysely-postgres-js@2.0.0", "npm:kysely@~0.27.4", diff --git a/src/config.ts b/src/config.ts index b65e0cfd..0164182a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -293,7 +293,7 @@ class Conf { } /** Languages this server wishes to highlight. Used when querying trends.*/ static get preferredLanguages(): LanguageCode[] | undefined { - return Deno.env.get('DITTO_LANGUAGES')?.split(',')?.filter(ISO6391.validate) as LanguageCode[]; + return Deno.env.get('DITTO_LANGUAGES')?.split(',')?.filter(ISO6391.validate); } /** Translation provider used to translate posts. */ static get translationProvider(): string | undefined { diff --git a/src/schema.ts b/src/schema.ts index b55a1f9a..0fce60d4 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -60,7 +60,7 @@ const languageSchema = z.string().transform((val, ctx) => { }); return z.NEVER; } - return val as LanguageCode; + return val; }); const localeSchema = z.string().transform((val, ctx) => { diff --git a/src/test.ts b/src/test.ts index 4e813f05..95aa2872 100644 --- a/src/test.ts +++ b/src/test.ts @@ -75,7 +75,7 @@ export function getLanguage(text: string): LanguageCode | undefined { const [iso6393] = topResult; const locale = new Intl.Locale(iso6393); if (ISO6391.validate(locale.language)) { - return locale.language as LanguageCode; + return locale.language; } } return; diff --git a/src/translators/DeepLTranslator.ts b/src/translators/DeepLTranslator.ts index 26067379..d1cefaaa 100644 --- a/src/translators/DeepLTranslator.ts +++ b/src/translators/DeepLTranslator.ts @@ -36,7 +36,7 @@ export class DeepLTranslator implements DittoTranslator { return { results: translations.map((value) => value.text), - source_lang: translations[0]?.detected_source_language as LanguageCode, + source_lang: translations[0]?.detected_source_language, }; } diff --git a/src/utils/language.ts b/src/utils/language.ts index 4b6e3807..b95e3e78 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -46,7 +46,7 @@ export function detectLanguage(text: string, minConfidence: number): LanguageCod const locale = new Intl.Locale(iso6393); if (confidence >= minConfidence && ISO6391.validate(locale.language)) { - return locale.language as LanguageCode; + return locale.language; } } } diff --git a/src/utils/search.ts b/src/utils/search.ts index 17a625bd..f44e00c8 100644 --- a/src/utils/search.ts +++ b/src/utils/search.ts @@ -79,14 +79,27 @@ export async function getIdsBySearch( } } - for (const [key, values] of Object.entries(ext)) { - if (key === 'domain') continue; + for (let [key, values] of Object.entries(ext)) { + if (key === 'domain' || key === '-domain') continue; - query = query.where((eb) => - eb.or( - values.map((value) => eb('nostr_events.search_ext', '@>', { [key]: value })), - ) - ); + let negated = false; + + if (key.startsWith('-')) { + key = key.slice(1); + negated = true; + } + + query = query.where((eb) => { + if (negated) { + return eb.and( + values.map((value) => eb.not(eb('nostr_events.search_ext', '@>', { [key]: value }))), + ); + } else { + return eb.or( + values.map((value) => eb('nostr_events.search_ext', '@>', { [key]: value })), + ); + } + }); } if (domains.size) {