Merge branch 'chinwag-next'
This commit is contained in:
commit
095ce4fb34
2690 changed files with 96825 additions and 58372 deletions
|
|
@ -1,43 +0,0 @@
|
|||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
// @ts-check
|
||||
|
||||
// @ts-ignore - This needs to be a CJS file (eslint does not yet support ESM configs), and TS is complaining we use require
|
||||
const { defineConfig } = require('eslint-define-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: ['../.eslintrc.js'],
|
||||
env: {
|
||||
browser: false,
|
||||
},
|
||||
parserOptions: {
|
||||
project: true,
|
||||
tsconfigRootDir: __dirname,
|
||||
ecmaFeatures: {
|
||||
jsx: false,
|
||||
},
|
||||
ecmaVersion: 2021,
|
||||
},
|
||||
rules: {
|
||||
// In the streaming server we need to delete some variables to ensure
|
||||
// garbage collection takes place on the values referenced by those objects;
|
||||
// The alternative is to declare the variable as nullable, but then we need
|
||||
// to assert it's in existence before every use, which becomes much harder
|
||||
// to maintain.
|
||||
'no-delete-var': 'off',
|
||||
|
||||
// This overrides the base configuration for this rule to pick up
|
||||
// dependencies for the streaming server from the correct package.json file.
|
||||
'import/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: ['streaming/.eslintrc.cjs'],
|
||||
optionalDependencies: false,
|
||||
peerDependencies: false,
|
||||
includeTypes: true,
|
||||
packageDir: __dirname,
|
||||
},
|
||||
],
|
||||
'import/extensions': ['error', 'always'],
|
||||
},
|
||||
});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# syntax=docker/dockerfile:1.9
|
||||
# syntax=docker/dockerfile:1.12
|
||||
|
||||
# Please see https://docs.docker.com/engine/reference/builder for information about
|
||||
# the extended buildx capabilities used in this file.
|
||||
|
|
@ -6,14 +6,15 @@
|
|||
# See: https://docs.docker.com/build/building/multi-platform/
|
||||
ARG TARGETPLATFORM=${TARGETPLATFORM}
|
||||
ARG BUILDPLATFORM=${BUILDPLATFORM}
|
||||
ARG BASE_REGISTRY="docker.io"
|
||||
|
||||
# Node version to use in base image, change with [--build-arg NODE_MAJOR_VERSION="20"]
|
||||
# renovate: datasource=node-version depName=node
|
||||
ARG NODE_MAJOR_VERSION="20"
|
||||
ARG NODE_MAJOR_VERSION="22"
|
||||
# Debian image to use for base image, change with [--build-arg DEBIAN_VERSION="bookworm"]
|
||||
ARG DEBIAN_VERSION="bookworm"
|
||||
# Node image to use for base image based on combined variables (ex: 20-bookworm-slim)
|
||||
FROM docker.io/node:${NODE_MAJOR_VERSION}-${DEBIAN_VERSION}-slim AS streaming
|
||||
FROM ${BASE_REGISTRY}/node:${NODE_MAJOR_VERSION}-${DEBIAN_VERSION}-slim AS streaming
|
||||
|
||||
# Resulting version string is vX.X.X-MASTODON_VERSION_PRERELEASE+MASTODON_VERSION_METADATA
|
||||
# Example: v4.3.0-nightly.2023.11.09+pr-123456
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@ export function configFromEnv(env, environment) {
|
|||
password: env.DB_PASS || pg.defaults.password,
|
||||
database: env.DB_NAME || 'mastodon_development',
|
||||
host: env.DB_HOST || pg.defaults.host,
|
||||
port: parseIntFromEnvValue(env.DB_PORT, pg.defaults.port ?? 5432, 'DB_PORT')
|
||||
port: parseIntFromEnvValue(
|
||||
env.DB_PORT,
|
||||
pg.defaults.port ?? 5432,
|
||||
'DB_PORT',
|
||||
),
|
||||
},
|
||||
|
||||
production: {
|
||||
|
|
@ -24,7 +28,7 @@ export function configFromEnv(env, environment) {
|
|||
password: env.DB_PASS || '',
|
||||
database: env.DB_NAME || 'mastodon_production',
|
||||
host: env.DB_HOST || 'localhost',
|
||||
port: parseIntFromEnvValue(env.DB_PORT, 5432, 'DB_PORT')
|
||||
port: parseIntFromEnvValue(env.DB_PORT, 5432, 'DB_PORT'),
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -46,25 +50,34 @@ export function configFromEnv(env, environment) {
|
|||
// https://github.com/brianc/node-postgres/issues/2280
|
||||
//
|
||||
// FIXME: clean up once brianc/node-postgres#3128 lands
|
||||
if (typeof parsedUrl.password === 'string') baseConfig.password = parsedUrl.password;
|
||||
if (typeof parsedUrl.password === 'string')
|
||||
baseConfig.password = parsedUrl.password;
|
||||
if (typeof parsedUrl.host === 'string') baseConfig.host = parsedUrl.host;
|
||||
if (typeof parsedUrl.user === 'string') baseConfig.user = parsedUrl.user;
|
||||
if (typeof parsedUrl.port === 'string' && parsedUrl.port) {
|
||||
const parsedPort = parseInt(parsedUrl.port, 10);
|
||||
if (isNaN(parsedPort)) {
|
||||
throw new Error('Invalid port specified in DATABASE_URL environment variable');
|
||||
throw new Error(
|
||||
'Invalid port specified in DATABASE_URL environment variable',
|
||||
);
|
||||
}
|
||||
baseConfig.port = parsedPort;
|
||||
}
|
||||
if (typeof parsedUrl.database === 'string') baseConfig.database = parsedUrl.database;
|
||||
if (typeof parsedUrl.options === 'string') baseConfig.options = parsedUrl.options;
|
||||
if (typeof parsedUrl.database === 'string')
|
||||
baseConfig.database = parsedUrl.database;
|
||||
if (typeof parsedUrl.options === 'string')
|
||||
baseConfig.options = parsedUrl.options;
|
||||
|
||||
// The pg-connection-string type definition isn't correct, as parsedUrl.ssl
|
||||
// can absolutely be an Object, this is to work around these incorrect
|
||||
// types, including the casting of parsedUrl.ssl to Record<string, any>
|
||||
if (typeof parsedUrl.ssl === 'boolean') {
|
||||
baseConfig.ssl = parsedUrl.ssl;
|
||||
} else if (typeof parsedUrl.ssl === 'object' && !Array.isArray(parsedUrl.ssl) && parsedUrl.ssl !== null) {
|
||||
} else if (
|
||||
typeof parsedUrl.ssl === 'object' &&
|
||||
!Array.isArray(parsedUrl.ssl) &&
|
||||
parsedUrl.ssl !== null
|
||||
) {
|
||||
/** @type {Record<string, any>} */
|
||||
const sslOptions = parsedUrl.ssl;
|
||||
baseConfig.ssl = {};
|
||||
|
|
@ -83,17 +96,17 @@ export function configFromEnv(env, environment) {
|
|||
baseConfig = pgConfigs[environment];
|
||||
|
||||
if (env.DB_SSLMODE) {
|
||||
switch(env.DB_SSLMODE) {
|
||||
case 'disable':
|
||||
case '':
|
||||
baseConfig.ssl = false;
|
||||
break;
|
||||
case 'no-verify':
|
||||
baseConfig.ssl = { rejectUnauthorized: false };
|
||||
break;
|
||||
default:
|
||||
baseConfig.ssl = {};
|
||||
break;
|
||||
switch (env.DB_SSLMODE) {
|
||||
case 'disable':
|
||||
case '':
|
||||
baseConfig.ssl = false;
|
||||
break;
|
||||
case 'no-verify':
|
||||
baseConfig.ssl = { rejectUnauthorized: false };
|
||||
break;
|
||||
default:
|
||||
baseConfig.ssl = {};
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -116,13 +129,51 @@ let pool;
|
|||
/**
|
||||
*
|
||||
* @param {pg.PoolConfig} config
|
||||
* @param {string} environment
|
||||
* @param {import('pino').Logger} logger
|
||||
* @returns {pg.Pool}
|
||||
*/
|
||||
export function getPool(config) {
|
||||
export function getPool(config, environment, logger) {
|
||||
if (pool) {
|
||||
return pool;
|
||||
}
|
||||
|
||||
pool = new pg.Pool(config);
|
||||
|
||||
// Setup logging on pool.query and client.query for checked out clients:
|
||||
// This is taken from: https://node-postgres.com/guides/project-structure
|
||||
if (environment === 'development') {
|
||||
const logQuery = (originalQuery) => {
|
||||
return async (queryTextOrConfig, values, ...rest) => {
|
||||
const start = process.hrtime();
|
||||
|
||||
const result = await originalQuery.apply(pool, [
|
||||
queryTextOrConfig,
|
||||
values,
|
||||
...rest,
|
||||
]);
|
||||
|
||||
const duration = process.hrtime(start);
|
||||
const durationInMs = (duration[0] * 1000000000 + duration[1]) / 1000000;
|
||||
|
||||
logger.debug(
|
||||
{
|
||||
query: queryTextOrConfig,
|
||||
values,
|
||||
duration: durationInMs,
|
||||
},
|
||||
'Executed database query',
|
||||
);
|
||||
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
pool.on('connect', (client) => {
|
||||
const originalQuery = client.query.bind(client);
|
||||
client.query = logQuery(originalQuery);
|
||||
});
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
|
|
|||
49
streaming/eslint.config.mjs
Normal file
49
streaming/eslint.config.mjs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// @ts-check
|
||||
|
||||
import path from 'node:path';
|
||||
|
||||
import globals from 'globals';
|
||||
import tseslint from 'typescript-eslint';
|
||||
|
||||
// eslint-disable-next-line import/no-relative-packages -- Must import from the root
|
||||
import { baseConfig } from '../eslint.config.mjs';
|
||||
|
||||
export default tseslint.config([
|
||||
baseConfig,
|
||||
{
|
||||
languageOptions: {
|
||||
globals: globals.node,
|
||||
|
||||
parser: tseslint.parser,
|
||||
ecmaVersion: 2021,
|
||||
sourceType: 'module',
|
||||
},
|
||||
|
||||
settings: {
|
||||
'import/ignore': ['node_modules', '\\.(json)$'],
|
||||
'import/resolver': {
|
||||
typescript: {
|
||||
project: path.resolve(import.meta.dirname, './tsconfig.json'),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
rules: {
|
||||
// In the streaming server we need to delete some variables to ensure
|
||||
// garbage collection takes place on the values referenced by those objects;
|
||||
// The alternative is to declare the variable as nullable, but then we need
|
||||
// to assert it's in existence before every use, which becomes much harder
|
||||
// to maintain.
|
||||
'no-delete-var': 'off',
|
||||
|
||||
'import/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: ['**/*.config.mjs'],
|
||||
},
|
||||
],
|
||||
|
||||
'import/extensions': ['error', 'always'],
|
||||
},
|
||||
},
|
||||
]);
|
||||
1047
streaming/index.js
1047
streaming/index.js
File diff suppressed because it is too large
Load diff
7
streaming/lint-staged.config.mjs
Normal file
7
streaming/lint-staged.config.mjs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const config = {
|
||||
'*': 'prettier --ignore-unknown --write',
|
||||
'*.{js,ts}': 'eslint --fix',
|
||||
'**/*.ts': () => 'tsc -p tsconfig.json --noEmit',
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name": "@mastodon/streaming",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"packageManager": "yarn@4.5.0",
|
||||
"packageManager": "yarn@4.9.2",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
"node": ">=20"
|
||||
},
|
||||
"description": "Mastodon's Streaming Server",
|
||||
"private": true,
|
||||
|
|
@ -21,24 +21,26 @@
|
|||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
"ioredis": "^5.3.2",
|
||||
"jsdom": "^25.0.0",
|
||||
"jsdom": "^26.0.0",
|
||||
"pg": "^8.5.0",
|
||||
"pg-connection-string": "^2.6.0",
|
||||
"pino": "^9.0.0",
|
||||
"pino-http": "^10.0.0",
|
||||
"prom-client": "^15.0.0",
|
||||
"uuid": "^10.0.0",
|
||||
"uuid": "^11.0.0",
|
||||
"ws": "^8.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.23.0",
|
||||
"@types/cors": "^2.8.16",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/pg": "^8.6.6",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@types/ws": "^8.5.9",
|
||||
"eslint-define-config": "^2.0.0",
|
||||
"pino-pretty": "^11.0.0",
|
||||
"typescript": "^5.0.4"
|
||||
"globals": "^16.0.0",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"typescript": "~5.7.3",
|
||||
"typescript-eslint": "^8.28.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"bufferutil": "^4.0.7",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { parseIntFromEnvValue } from './utils.js';
|
|||
|
||||
/**
|
||||
* @typedef RedisConfiguration
|
||||
* @property {string|undefined} namespace
|
||||
* @property {string|undefined} url
|
||||
* @property {import('ioredis').RedisOptions} options
|
||||
*/
|
||||
|
|
@ -31,7 +30,11 @@ function hasSentinelConfiguration(env) {
|
|||
*/
|
||||
function getSentinelConfiguration(env, commonOptions) {
|
||||
const redisDatabase = parseIntFromEnvValue(env.REDIS_DB, 0, 'REDIS_DB');
|
||||
const sentinelPort = parseIntFromEnvValue(env.REDIS_SENTINEL_PORT, 26379, 'REDIS_SENTINEL_PORT');
|
||||
const sentinelPort = parseIntFromEnvValue(
|
||||
env.REDIS_SENTINEL_PORT,
|
||||
26379,
|
||||
'REDIS_SENTINEL_PORT',
|
||||
);
|
||||
|
||||
const sentinels = env.REDIS_SENTINELS.split(',').map((sentinel) => {
|
||||
const [host, port] = sentinel.split(':', 2);
|
||||
|
|
@ -43,7 +46,7 @@ function getSentinelConfiguration(env, commonOptions) {
|
|||
// Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
|
||||
// only allowing IPv4 connections:
|
||||
// https://github.com/redis/ioredis/issues/1576
|
||||
family: 0
|
||||
family: 0,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
@ -64,15 +67,13 @@ function getSentinelConfiguration(env, commonOptions) {
|
|||
* @returns {RedisConfiguration} configuration for the Redis connection
|
||||
*/
|
||||
export function configFromEnv(env) {
|
||||
const redisNamespace = env.REDIS_NAMESPACE;
|
||||
|
||||
// These options apply for both REDIS_URL based connections and connections
|
||||
// using the other REDIS_* environment variables:
|
||||
const commonOptions = {
|
||||
// Force support for both IPv6 and IPv4, by default ioredis sets this to 4,
|
||||
// only allowing IPv4 connections:
|
||||
// https://github.com/redis/ioredis/issues/1576
|
||||
family: 0
|
||||
family: 0,
|
||||
// Note: we don't use auto-prefixing of keys since this doesn't apply to
|
||||
// subscribe/unsubscribe which have "channel" instead of "key" arguments
|
||||
};
|
||||
|
|
@ -83,7 +84,6 @@ export function configFromEnv(env) {
|
|||
return {
|
||||
url: env.REDIS_URL,
|
||||
options: commonOptions,
|
||||
namespace: redisNamespace
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +91,6 @@ export function configFromEnv(env) {
|
|||
if (hasSentinelConfiguration(env)) {
|
||||
return {
|
||||
options: getSentinelConfiguration(env, commonOptions),
|
||||
namespace: redisNamespace
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +110,6 @@ export function configFromEnv(env) {
|
|||
|
||||
return {
|
||||
options,
|
||||
namespace: redisNamespace
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,5 +8,5 @@
|
|||
"tsBuildInfoFile": "../tmp/cache/streaming/tsconfig.tsbuildinfo",
|
||||
"paths": {}
|
||||
},
|
||||
"include": ["./*.js", "./.eslintrc.cjs"]
|
||||
"include": ["./*.js"]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue