mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'ditto-db' into 'main'
Add @ditto/db package See merge request soapbox-pub/ditto!667
This commit is contained in:
commit
eb63658b25
78 changed files with 126 additions and 93 deletions
|
|
@ -10,7 +10,7 @@ test:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- deno fmt --check
|
- deno fmt --check
|
||||||
- deno lint
|
- deno lint --allow-import
|
||||||
- deno task check
|
- deno task check
|
||||||
- deno task test --coverage=cov_profile
|
- deno task test --coverage=cov_profile
|
||||||
- deno coverage cov_profile
|
- deno coverage cov_profile
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
"workspace": [
|
"workspace": [
|
||||||
"./packages/api",
|
"./packages/api",
|
||||||
"./packages/conf",
|
"./packages/conf",
|
||||||
|
"./packages/db",
|
||||||
"./packages/ditto"
|
"./packages/ditto"
|
||||||
],
|
],
|
||||||
"tasks": {
|
"tasks": {
|
||||||
|
|
|
||||||
6
packages/db/DittoDB.test.ts
Normal file
6
packages/db/DittoDB.test.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import { DittoDB } from './DittoDB.ts';
|
||||||
|
|
||||||
|
Deno.test('DittoDB', async () => {
|
||||||
|
const db = DittoDB.create('memory://');
|
||||||
|
await DittoDB.migrate(db.kysely);
|
||||||
|
});
|
||||||
|
|
@ -2,15 +2,17 @@ import fs from 'node:fs/promises';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import { JsonValue } from '@std/json';
|
import { FileMigrationProvider, type Kysely, Migrator } from 'kysely';
|
||||||
import { FileMigrationProvider, Kysely, Migrator } from 'kysely';
|
|
||||||
|
|
||||||
import { DittoPglite } from '@/db/adapters/DittoPglite.ts';
|
|
||||||
import { DittoPostgres } from '@/db/adapters/DittoPostgres.ts';
|
|
||||||
import { DittoDatabase, DittoDatabaseOpts } from '@/db/DittoDatabase.ts';
|
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { errorJson } from '@/utils/log.ts';
|
import { errorJson } from '@/utils/log.ts';
|
||||||
|
|
||||||
|
import { DittoPglite } from './adapters/DittoPglite.ts';
|
||||||
|
import { DittoPostgres } from './adapters/DittoPostgres.ts';
|
||||||
|
|
||||||
|
import type { JsonValue } from '@std/json';
|
||||||
|
import type { DittoDatabase, DittoDatabaseOpts } from './DittoDatabase.ts';
|
||||||
|
import type { DittoTables } from './DittoTables.ts';
|
||||||
|
|
||||||
export class DittoDB {
|
export class DittoDB {
|
||||||
/** Open a new database connection. */
|
/** Open a new database connection. */
|
||||||
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
import type { DittoTables } from './DittoTables.ts';
|
||||||
|
|
||||||
export interface DittoDatabase {
|
export interface DittoDatabase {
|
||||||
readonly kysely: Kysely<DittoTables>;
|
readonly kysely: Kysely<DittoTables>;
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { Generated } from 'kysely';
|
import type { NPostgresSchema } from '@nostrify/db';
|
||||||
|
import type { Generated } from 'kysely';
|
||||||
import { NPostgresSchema } from '@nostrify/db';
|
|
||||||
|
|
||||||
export interface DittoTables extends NPostgresSchema {
|
export interface DittoTables extends NPostgresSchema {
|
||||||
auth_tokens: AuthTokenRow;
|
auth_tokens: AuthTokenRow;
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { logi, LogiValue } from '@soapbox/logi';
|
import { logi, type LogiValue } from '@soapbox/logi';
|
||||||
import { Logger } from 'kysely';
|
|
||||||
|
|
||||||
import { dbQueriesCounter, dbQueryDurationHistogram } from '@/metrics.ts';
|
import { dbQueriesCounter, dbQueryDurationHistogram } from '@/metrics.ts';
|
||||||
import { errorJson } from '@/utils/log.ts';
|
|
||||||
|
import type { Logger } from 'kysely';
|
||||||
|
|
||||||
/** Log the SQL for queries. */
|
/** Log the SQL for queries. */
|
||||||
export const KyselyLogger: Logger = (event) => {
|
export const KyselyLogger: Logger = (event) => {
|
||||||
|
|
@ -24,7 +24,7 @@ export const KyselyLogger: Logger = (event) => {
|
||||||
ns: 'ditto.sql',
|
ns: 'ditto.sql',
|
||||||
sql,
|
sql,
|
||||||
parameters: parameters as LogiValue,
|
parameters: parameters as LogiValue,
|
||||||
error: errorJson(event.error),
|
error: event.error instanceof Error ? event.error : null,
|
||||||
duration,
|
duration,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
13
packages/db/adapters/DittoPglite.test.ts
Normal file
13
packages/db/adapters/DittoPglite.test.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { assertEquals } from '@std/assert';
|
||||||
|
|
||||||
|
import { DittoPglite } from './DittoPglite.ts';
|
||||||
|
|
||||||
|
Deno.test('DittoPglite.create', async () => {
|
||||||
|
const db = DittoPglite.create('memory://');
|
||||||
|
|
||||||
|
assertEquals(db.poolSize, 1);
|
||||||
|
assertEquals(db.availableConnections, 1);
|
||||||
|
|
||||||
|
await db.kysely.destroy();
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
|
});
|
||||||
|
|
@ -3,10 +3,11 @@ import { pg_trgm } from '@electric-sql/pglite/contrib/pg_trgm';
|
||||||
import { PgliteDialect } from '@soapbox/kysely-pglite';
|
import { PgliteDialect } from '@soapbox/kysely-pglite';
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
|
|
||||||
import { DittoDatabase, DittoDatabaseOpts } from '@/db/DittoDatabase.ts';
|
import { KyselyLogger } from '../KyselyLogger.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
import { isWorker } from '../utils/worker.ts';
|
||||||
import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
|
||||||
import { isWorker } from '@/utils/worker.ts';
|
import type { DittoDatabase, DittoDatabaseOpts } from '../DittoDatabase.ts';
|
||||||
|
import type { DittoTables } from '../DittoTables.ts';
|
||||||
|
|
||||||
export class DittoPglite {
|
export class DittoPglite {
|
||||||
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import {
|
import {
|
||||||
BinaryOperationNode,
|
type BinaryOperationNode,
|
||||||
FunctionNode,
|
FunctionNode,
|
||||||
Kysely,
|
Kysely,
|
||||||
OperatorNode,
|
OperatorNode,
|
||||||
|
|
@ -9,12 +9,13 @@ import {
|
||||||
PrimitiveValueListNode,
|
PrimitiveValueListNode,
|
||||||
ValueNode,
|
ValueNode,
|
||||||
} from 'kysely';
|
} from 'kysely';
|
||||||
import { PostgresJSDialectConfig, PostgresJSDriver } from 'kysely-postgres-js';
|
import { type PostgresJSDialectConfig, PostgresJSDriver } from 'kysely-postgres-js';
|
||||||
import postgres from 'postgres';
|
import postgres from 'postgres';
|
||||||
|
|
||||||
import { DittoDatabase, DittoDatabaseOpts } from '@/db/DittoDatabase.ts';
|
import { KyselyLogger } from '../KyselyLogger.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { KyselyLogger } from '@/db/KyselyLogger.ts';
|
import type { DittoDatabase, DittoDatabaseOpts } from '../DittoDatabase.ts';
|
||||||
|
import type { DittoTables } from '../DittoTables.ts';
|
||||||
|
|
||||||
export class DittoPostgres {
|
export class DittoPostgres {
|
||||||
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
static create(databaseUrl: string, opts?: DittoDatabaseOpts): DittoDatabase {
|
||||||
6
packages/db/deno.json
Normal file
6
packages/db/deno.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name": "@ditto/db",
|
||||||
|
"exports": {
|
||||||
|
".": "./mod.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(_db: Kysely<unknown>): Promise<void> {
|
export async function up(_db: Kysely<unknown>): Promise<void> {
|
||||||
// This migration used to create an FTS table for SQLite, but SQLite support was removed.
|
// This migration used to create an FTS table for SQLite, but SQLite support was removed.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(_db: Kysely<unknown>): Promise<void> {
|
export async function up(_db: Kysely<unknown>): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(_db: Kysely<unknown>): Promise<void> {
|
export async function up(_db: Kysely<unknown>): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(_db: Kysely<unknown>): Promise<void> {
|
export async function up(_db: Kysely<unknown>): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(_db: Kysely<unknown>): Promise<void> {
|
export async function up(_db: Kysely<unknown>): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.dropTable('users').ifExists().execute();
|
await db.schema.dropTable('users').ifExists().execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.dropIndex('idx_tags_tag').execute();
|
await db.schema.dropIndex('idx_tags_tag').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.alterTable('events').addColumn('deleted_at', 'integer').execute();
|
await db.schema.alterTable('events').addColumn('deleted_at', 'integer').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.createIndex('idx_author_stats_pubkey').on('author_stats').column('pubkey').execute();
|
await db.schema.createIndex('idx_author_stats_pubkey').on('author_stats').column('pubkey').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.dropTable('relays').execute();
|
await db.schema.dropTable('relays').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.alterTable('events').renameTo('nostr_events').execute();
|
await db.schema.alterTable('events').renameTo('nostr_events').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.createTable('nostr_pgfts')
|
await db.schema.createTable('nostr_pgfts')
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
// Create new table and indexes.
|
// Create new table and indexes.
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.dropTable('unattached_media').execute();
|
await db.schema.dropTable('unattached_media').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.alterTable('nostr_events').addColumn('language', 'char(2)').execute();
|
await db.schema.alterTable('nostr_events').addColumn('language', 'char(2)').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { aesEncrypt } from '@/utils/aes.ts';
|
import { aesEncrypt } from '@/utils/aes.ts';
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await sql`
|
await sql`
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await sql`DROP TRIGGER IF EXISTS nostr_event_trigger ON nostr_events`.execute(db);
|
await sql`DROP TRIGGER IF EXISTS nostr_event_trigger ON nostr_events`.execute(db);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.alterTable('nostr_events').dropColumn('language').execute();
|
await db.schema.alterTable('nostr_events').dropColumn('language').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.alterTable('nostr_events').alterColumn('search_ext', (col) => col.dropDefault()).execute();
|
await db.schema.alterTable('nostr_events').alterColumn('search_ext', (col) => col.dropDefault()).execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import type { Kysely } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.dropTable('pubkey_domains').execute();
|
await db.schema.dropTable('pubkey_domains').execute();
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await sql`DROP TRIGGER IF EXISTS nostr_event_trigger ON nostr_events`.execute(db);
|
await sql`DROP TRIGGER IF EXISTS nostr_event_trigger ON nostr_events`.execute(db);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely, sql } from 'kysely';
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<unknown>): Promise<void> {
|
export async function up(db: Kysely<unknown>): Promise<void> {
|
||||||
await sql`
|
await sql`
|
||||||
4
packages/db/mod.ts
Normal file
4
packages/db/mod.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
export { DittoDB } from './DittoDB.ts';
|
||||||
|
|
||||||
|
export type { DittoDatabase } from './DittoDatabase.ts';
|
||||||
|
export type { DittoTables } from './DittoTables.ts';
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
import { assertEquals } from '@std/assert';
|
import { assertEquals } from '@std/assert';
|
||||||
|
|
||||||
import { isWorker } from '@/utils/worker.ts';
|
import { isWorker } from './worker.ts';
|
||||||
|
|
||||||
Deno.test('isWorker from the main thread returns false', () => {
|
Deno.test('isWorker from the main thread returns false', () => {
|
||||||
assertEquals(isWorker(), false);
|
assertEquals(isWorker(), false);
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('isWorker from a worker thread returns true', async () => {
|
Deno.test('isWorker from a worker thread returns true', async () => {
|
||||||
|
const url = new URL('./worker.ts', import.meta.url);
|
||||||
|
|
||||||
const script = `
|
const script = `
|
||||||
import { isWorker } from '@/utils/worker.ts';
|
import { isWorker } from '${url.href}';
|
||||||
postMessage(isWorker());
|
postMessage(isWorker());
|
||||||
self.close();
|
self.close();
|
||||||
`;
|
`;
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { confMw } from '@ditto/api/middleware';
|
import { confMw } from '@ditto/api/middleware';
|
||||||
import { type DittoConf } from '@ditto/conf';
|
import { type DittoConf } from '@ditto/conf';
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { type Context, Env as HonoEnv, Handler, Hono, Input as HonoInput, MiddlewareHandler } from '@hono/hono';
|
import { type Context, Env as HonoEnv, Handler, Hono, Input as HonoInput, MiddlewareHandler } from '@hono/hono';
|
||||||
import { every } from '@hono/hono/combine';
|
import { every } from '@hono/hono/combine';
|
||||||
import { cors } from '@hono/hono/cors';
|
import { cors } from '@hono/hono/cors';
|
||||||
|
|
@ -9,7 +10,6 @@ import { Kysely } from 'kysely';
|
||||||
|
|
||||||
import '@/startup.ts';
|
import '@/startup.ts';
|
||||||
|
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { Time } from '@/utils/time.ts';
|
import { Time } from '@/utils/time.ts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { NKinds, NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
import { NKinds, NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import { Kysely, UpdateObject } from 'kysely';
|
import { Kysely, UpdateObject } from 'kysely';
|
||||||
|
|
@ -6,7 +7,6 @@ import { z } from 'zod';
|
||||||
|
|
||||||
import { pipelineEncounters } from '@/caches/pipelineEncounters.ts';
|
import { pipelineEncounters } from '@/caches/pipelineEncounters.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { DittoPush } from '@/DittoPush.ts';
|
import { DittoPush } from '@/DittoPush.ts';
|
||||||
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { pipelineEventsCounter, policyEventsCounter, webPushNotificationsCounter } from '@/metrics.ts';
|
import { pipelineEventsCounter, policyEventsCounter, webPushNotificationsCounter } from '@/metrics.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
// deno-lint-ignore-file require-await
|
// deno-lint-ignore-file require-await
|
||||||
|
import { type DittoDatabase, DittoDB } from '@ditto/db';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoDatabase } from '@/db/DittoDatabase.ts';
|
|
||||||
import { DittoDB } from '@/db/DittoDB.ts';
|
|
||||||
import { internalSubscriptionsSizeGauge } from '@/metrics.ts';
|
import { internalSubscriptionsSizeGauge } from '@/metrics.ts';
|
||||||
import { wsUrlSchema } from '@/schema.ts';
|
import { wsUrlSchema } from '@/schema.ts';
|
||||||
import { AdminStore } from '@/storages/AdminStore.ts';
|
import { AdminStore } from '@/storages/AdminStore.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// deno-lint-ignore-file require-await
|
// deno-lint-ignore-file require-await
|
||||||
|
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { NPostgres, NPostgresSchema } from '@nostrify/db';
|
import { NPostgres, NPostgresSchema } from '@nostrify/db';
|
||||||
import { NIP50, NKinds, NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NIP50, NKinds, NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
|
|
@ -11,7 +12,6 @@ import { nip27 } from 'nostr-tools';
|
||||||
import tldts from 'tldts';
|
import tldts from 'tldts';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { dbEventsCounter } from '@/metrics.ts';
|
import { dbEventsCounter } from '@/metrics.ts';
|
||||||
import { RelayError } from '@/RelayError.ts';
|
import { RelayError } from '@/RelayError.ts';
|
||||||
import { isNostrId } from '@/utils.ts';
|
import { isNostrId } from '@/utils.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { NStore } from '@nostrify/nostrify';
|
import { NStore } from '@nostrify/nostrify';
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
import { matchFilter } from 'nostr-tools';
|
import { matchFilter } from 'nostr-tools';
|
||||||
import { NSchema as n } from '@nostrify/nostrify';
|
import { NSchema as n } from '@nostrify/nostrify';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||||
import { fallbackAuthor } from '@/utils.ts';
|
import { fallbackAuthor } from '@/utils.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
|
import { DittoDB } from '@ditto/db';
|
||||||
import ISO6391, { LanguageCode } from 'iso-639-1';
|
import ISO6391, { LanguageCode } from 'iso-639-1';
|
||||||
import lande from 'lande';
|
import lande from 'lande';
|
||||||
import { NostrEvent } from '@nostrify/nostrify';
|
import { NostrEvent } from '@nostrify/nostrify';
|
||||||
import { finalizeEvent, generateSecretKey } from 'nostr-tools';
|
import { finalizeEvent, generateSecretKey } from 'nostr-tools';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoDB } from '@/db/DittoDB.ts';
|
|
||||||
import { EventsDB } from '@/storages/EventsDB.ts';
|
import { EventsDB } from '@/storages/EventsDB.ts';
|
||||||
import { purifyEvent } from '@/utils/purify.ts';
|
import { purifyEvent } from '@/utils/purify.ts';
|
||||||
import { sql } from 'kysely';
|
import { sql } from 'kysely';
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { NostrFilter } from '@nostrify/nostrify';
|
import { NostrFilter } from '@nostrify/nostrify';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import { Kysely, sql } from 'kysely';
|
import { Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { handleEvent } from '@/pipeline.ts';
|
import { handleEvent } from '@/pipeline.ts';
|
||||||
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import { DOMParser } from '@b-fuze/deno-dom';
|
import { DOMParser } from '@b-fuze/deno-dom';
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { logi } from '@soapbox/logi';
|
import { logi } from '@soapbox/logi';
|
||||||
import { safeFetch } from '@soapbox/safe-fetch';
|
import { safeFetch } from '@soapbox/safe-fetch';
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
import tldts from 'tldts';
|
import tldts from 'tldts';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { cachedFaviconsSizeGauge } from '@/metrics.ts';
|
import { cachedFaviconsSizeGauge } from '@/metrics.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { nostrNow } from '@/utils.ts';
|
import { nostrNow } from '@/utils.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { Kysely, sql } from 'kysely';
|
import { Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
|
|
||||||
/** Get pubkeys whose name and NIP-05 is similar to 'q' */
|
/** Get pubkeys whose name and NIP-05 is similar to 'q' */
|
||||||
export async function getPubkeysBySearch(
|
export async function getPubkeysBySearch(
|
||||||
kysely: Kysely<DittoTables>,
|
kysely: Kysely<DittoTables>,
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
|
import { DittoTables } from '@ditto/db';
|
||||||
import { NostrEvent, NSchema as n, NStore } from '@nostrify/nostrify';
|
import { NostrEvent, NSchema as n, NStore } from '@nostrify/nostrify';
|
||||||
import { Insertable, Kysely, UpdateObject } from 'kysely';
|
import { Insertable, Kysely, UpdateObject } from 'kysely';
|
||||||
import { SetRequired } from 'type-fest';
|
import { SetRequired } from 'type-fest';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoTables } from '@/db/DittoTables.ts';
|
|
||||||
import { findQuoteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
import { findQuoteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
||||||
|
|
||||||
interface UpdateStatsOpts {
|
interface UpdateStatsOpts {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
import { DittoDB } from '@ditto/db';
|
||||||
import '@soapbox/safe-fetch/load';
|
import '@soapbox/safe-fetch/load';
|
||||||
import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/nostrify';
|
import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/nostrify';
|
||||||
import { ReadOnlyPolicy } from '@nostrify/policies';
|
import { ReadOnlyPolicy } from '@nostrify/policies';
|
||||||
import * as Comlink from 'comlink';
|
import * as Comlink from 'comlink';
|
||||||
|
|
||||||
import { DittoDB } from '@/db/DittoDB.ts';
|
|
||||||
import { EventsDB } from '@/storages/EventsDB.ts';
|
import { EventsDB } from '@/storages/EventsDB.ts';
|
||||||
|
|
||||||
// @ts-ignore Don't try to access the env from this worker.
|
// @ts-ignore Don't try to access the env from this worker.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue