mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
@ditto/config -> @ditto/conf, DittoConfig -> DittoConf
This commit is contained in:
parent
665be0c1b2
commit
02a7305ee9
15 changed files with 14 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"workspace": [
|
"workspace": [
|
||||||
"./packages/api",
|
"./packages/api",
|
||||||
"./packages/config",
|
"./packages/conf",
|
||||||
"./packages/ditto"
|
"./packages/ditto"
|
||||||
],
|
],
|
||||||
"tasks": {
|
"tasks": {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { DittoConfig } from '@ditto/config';
|
import { DittoConf } from '@ditto/conf';
|
||||||
|
|
||||||
import type { MiddlewareHandler } from '@hono/hono';
|
import type { MiddlewareHandler } from '@hono/hono';
|
||||||
|
|
||||||
/** Set Ditto config. */
|
/** Set Ditto config. */
|
||||||
export function confMw(
|
export function confMw(
|
||||||
env: { get(key: string): string | undefined },
|
env: { get(key: string): string | undefined },
|
||||||
): MiddlewareHandler<{ Variables: { conf: DittoConfig } }> {
|
): MiddlewareHandler<{ Variables: { conf: DittoConf } }> {
|
||||||
const conf = new DittoConfig(env);
|
const conf = new DittoConf(env);
|
||||||
|
|
||||||
return async (c, next) => {
|
return async (c, next) => {
|
||||||
c.set('conf', conf);
|
c.set('conf', conf);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import { HTTPException } from '@hono/hono/http-exception';
|
import { HTTPException } from '@hono/hono/http-exception';
|
||||||
|
|
||||||
import type { DittoConfig } from '@ditto/config';
|
import type { DittoConf } from '@ditto/conf';
|
||||||
import type { MiddlewareHandler } from '@hono/hono';
|
import type { MiddlewareHandler } from '@hono/hono';
|
||||||
|
|
||||||
/** Throws an error if conf isn't set. */
|
/** Throws an error if conf isn't set. */
|
||||||
export const confRequiredMw: MiddlewareHandler<{ Variables: { conf: DittoConfig } }> = async (c, next) => {
|
export const confRequiredMw: MiddlewareHandler<{ Variables: { conf: DittoConf } }> = async (c, next) => {
|
||||||
const { conf } = c.var;
|
const { conf } = c.var;
|
||||||
|
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { assertEquals, assertThrows } from '@std/assert';
|
import { assertEquals, assertThrows } from '@std/assert';
|
||||||
|
|
||||||
import { DittoConfig } from './DittoConfig.ts';
|
import { DittoConf } from './DittoConf.ts';
|
||||||
|
|
||||||
Deno.test('DittoConfig', async (t) => {
|
Deno.test('DittoConfig', async (t) => {
|
||||||
const env = new Map<string, string>([
|
const env = new Map<string, string>([
|
||||||
['DITTO_NSEC', 'nsec19shyxpuzd0cq2p5078fwnws7tyykypud6z205fzhlmlrs2vpz6hs83zwkw'],
|
['DITTO_NSEC', 'nsec19shyxpuzd0cq2p5078fwnws7tyykypud6z205fzhlmlrs2vpz6hs83zwkw'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const config = new DittoConfig(env);
|
const config = new DittoConf(env);
|
||||||
|
|
||||||
await t.step('nsec', () => {
|
await t.step('nsec', () => {
|
||||||
assertEquals(config.nsec, 'nsec19shyxpuzd0cq2p5078fwnws7tyykypud6z205fzhlmlrs2vpz6hs83zwkw');
|
assertEquals(config.nsec, 'nsec19shyxpuzd0cq2p5078fwnws7tyykypud6z205fzhlmlrs2vpz6hs83zwkw');
|
||||||
|
|
@ -20,7 +20,7 @@ Deno.test('DittoConfig', async (t) => {
|
||||||
|
|
||||||
Deno.test('DittoConfig defaults', async (t) => {
|
Deno.test('DittoConfig defaults', async (t) => {
|
||||||
const env = new Map<string, string>();
|
const env = new Map<string, string>();
|
||||||
const config = new DittoConfig(env);
|
const config = new DittoConf(env);
|
||||||
|
|
||||||
await t.step('nsec throws', () => {
|
await t.step('nsec throws', () => {
|
||||||
assertThrows(() => config.nsec);
|
assertThrows(() => config.nsec);
|
||||||
|
|
@ -9,7 +9,7 @@ import { optionalBooleanSchema, optionalNumberSchema } from './utils/schema.ts';
|
||||||
import { mergeURLPath } from './utils/url.ts';
|
import { mergeURLPath } from './utils/url.ts';
|
||||||
|
|
||||||
/** Ditto application-wide configuration. */
|
/** Ditto application-wide configuration. */
|
||||||
export class DittoConfig {
|
export class DittoConf {
|
||||||
constructor(private env: { get(key: string): string | undefined }) {}
|
constructor(private env: { get(key: string): string | undefined }) {}
|
||||||
|
|
||||||
/** Cached parsed admin pubkey value. */
|
/** Cached parsed admin pubkey value. */
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "@ditto/config",
|
"name": "@ditto/conf",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./mod.ts"
|
".": "./mod.ts"
|
||||||
1
packages/conf/mod.ts
Normal file
1
packages/conf/mod.ts
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export { DittoConf } from './DittoConf.ts';
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export { DittoConfig } from './DittoConfig.ts';
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { DittoConfig } from '@ditto/config';
|
import { DittoConf } from '@ditto/conf';
|
||||||
|
|
||||||
/** @deprecated Use middleware to set/get the config instead. */
|
/** @deprecated Use middleware to set/get the config instead. */
|
||||||
export const Conf = new DittoConfig(Deno.env);
|
export const Conf = new DittoConf(Deno.env);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue