Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ jobs:
with:
cache: true
experimental: true
log_level: ${{ runner.debug == '1' && 'debug' || 'info' }}
log_level: ${{ runner.debug == '1' && 'trace' || 'info' }}
- run: mise build && mise check
env:
MISE_LOG_LEVEL: ${{ runner.debug == '1' && 'trace' || 'info' }}

test:
strategy:
Expand All @@ -30,5 +32,9 @@ jobs:
with:
cache: true
experimental: true
log_level: ${{ runner.debug == '1' && 'debug' || 'info' }}
log_level: ${{ runner.debug == '1' && 'trace' || 'info' }}
- run: mise test
env:
MISE_LOG_LEVEL: ${{ runner.debug == '1' && 'trace' || 'info' }}
LOGTAPE_TEST_MODE: ${{ runner.debug == '1' && 'always' || 'on-failure' }}
LOGTAPE_TEST_LOWEST_LEVEL: ${{ runner.debug == '1' && 'trace' || 'debug' }}
1 change: 1 addition & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"import/consistent-type-specifier-style": "off",
"import/exports-last": "off",
"import/group-exports": "off",
"import/max-dependencies": ["warn", { "max": 20 }],
"import/no-default-export": "off",
"import/no-named-export": "off",
"import/no-namespace": "off",
Expand Down
23 changes: 22 additions & 1 deletion mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,20 @@ run = "pnpm run --parallel --recursive build"
[tasks.test]
description = "Run tests"
depends = ["build"]
run = "pnpm run --parallel --recursive test"
usage = '''
flag "-d --debug" help="Run tests in debug mode"
'''
run = '''
#!/usr/bin/env nu
if "usage_debug" in $env {
$env.LOGTAPE_TEST_MODE = "always"
$env.LOGTAPE_TEST_LOWEST_LEVEL = "trace"
} else {
$env.LOGTAPE_TEST_MODE = "on-failure"
$env.LOGTAPE_TEST_LOWEST_LEVEL = "debug"
}
pnpm run --parallel --recursive test
'''

[tasks.bump]
description = "Bump all package versions"
Expand Down Expand Up @@ -93,4 +106,12 @@ pnpm exec drizzle-kit generate ...$name ...$custom

[tasks.dev]
description = "Run the development server"
usage = '''
flag "-L --log-level <level>" {
choices "trace" "debug" "info" "warn" "error" "fatal"
default "debug"
help "Set log level"
}
flag "--log-output <path>" help="Write logs to a file"
'''
run = "node scripts/dev.mts"
4 changes: 4 additions & 0 deletions packages/drfed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"build": "tsdown"
},
"devDependencies": {
"@logtape/testing-node": "catalog:",
"@types/node": "catalog:",
"@types/pg": "catalog:",
"tsdown": "catalog:",
Expand All @@ -68,7 +69,10 @@
"@drfed/graphql": "workspace:*",
"@drfed/models": "workspace:*",
"@electric-sql/pglite": "catalog:",
"@logtape/drizzle-orm": "catalog:",
"@logtape/logtape": "catalog:",
"@optique/core": "^1.1.0",
"@optique/logtape": "catalog:",
"@optique/run": "^1.1.0",
"drizzle-orm": "catalog:",
"pg": "catalog:",
Expand Down
31 changes: 31 additions & 0 deletions packages/drfed/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { AsyncLocalStorage } from "node:async_hooks";
import process from "node:process";

import { createYogaServer } from "@drfed/graphql";
import { migrate } from "@drfed/models";
import { configure, getConsoleSink } from "@logtape/logtape";
import { createLoggingConfig } from "@optique/logtape";
import { run } from "@optique/run";
import { serve } from "srvx";

Expand All @@ -25,6 +28,7 @@ import metadata from "../package.json" with { type: "json" };
import type { Options } from "./parser.ts";
import program from "./program.ts";

// oxlint-disable-next-line max-lines-per-function
export async function main(): Promise<void> {
const options: Options = run(program, {
help: "option",
Expand All @@ -35,6 +39,33 @@ export async function main(): Promise<void> {
value: metadata.version,
},
});
const loggingConfig = await createLoggingConfig(
options.logging,
{},
{
contextLocalStorage: new AsyncLocalStorage(),
sinks: {
stderr: getConsoleSink({
levelMap: {
trace: "error",
debug: "error",
info: "error",
warning: "error",
error: "error",
fatal: "error",
},
}),
},
loggers: [
{
category: ["logtape", "meta"],
lowestLevel: "warning",
sinks: ["stderr"],
},
],
},
);
await configure(loggingConfig);
if (options.drizzle.migrate) {
await migrate({ credentials: options.drizzle.credentials });
}
Expand Down
5 changes: 5 additions & 0 deletions packages/drfed/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { relations, schema } from "@drfed/models";
import { getLogger } from "@logtape/drizzle-orm";
import { merge, object, or } from "@optique/core/constructs";
import { message, optionNames } from "@optique/core/message";
import { map, withDefault } from "@optique/core/modifiers";
import type { InferValue } from "@optique/core/parser";
import { option } from "@optique/core/primitives";
import { socketAddress, url } from "@optique/core/valueparser";
import { loggingOptions } from "@optique/logtape";
import { path } from "@optique/run/valueparser";
import { drizzle as drizzlePostgres } from "drizzle-orm/node-postgres";
import { drizzle as drizzlePglite } from "drizzle-orm/pglite";
Expand All @@ -43,6 +45,7 @@ const pgliteParser = map(
connection: { dataDir: dbPath },
relations,
schema,
logger: getLogger(),
}),
}),
);
Expand All @@ -67,11 +70,13 @@ const postgresParser = map(
},
relations,
schema,
logger: getLogger(),
}),
}),
);

export const parser = object({
logging: loggingOptions({ level: "option", short: "-L" }),
address: withDefault(
option("--listen", "-l", socketAddress({ requirePort: true }), {
description: message`The address to listen on.`,
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@
},
"devDependencies": {
"@electric-sql/pglite": "catalog:",
"@logtape/testing-node": "catalog:",
"@types/node": "catalog:",
"tsdown": "catalog:",
"typescript": "catalog:"
},
"dependencies": {
"@drfed/models": "workspace:*",
"@logtape/graphql-yoga": "catalog:",
"@logtape/logtape": "catalog:",
"@pothos/core": "^4.13.0",
"@pothos/plugin-drizzle": "^0.17.4",
"@pothos/plugin-relay": "^4.7.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { type Database, schema } from "@drfed/models";
import { describe, it } from "@logtape/testing-node/autoload";

import { withTestHarness } from "./harness.test.ts";

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/harness-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { schema } from "@drfed/models";
import { describe, it } from "@logtape/testing-node/autoload";

import { withTemporaryDatabase, withTestHarness } from "./harness.test.ts";

Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import type { Database } from "@drfed/models";
import { getYogaLogger } from "@logtape/graphql-yoga";
import {
type YogaServerInstance,
createYoga,
Expand All @@ -39,5 +40,6 @@ export function createYogaServer(
},
plugins: [useExecutionCancellation()],
schema,
logging: getYogaLogger(),
});
}
2 changes: 1 addition & 1 deletion packages/graphql/src/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { type Database, schema } from "@drfed/models";
import { describe, it } from "@logtape/testing-node/autoload";

import { withTestHarness } from "./harness.test.ts";

Expand Down
2 changes: 2 additions & 0 deletions packages/models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"test": "node --test"
},
"devDependencies": {
"@logtape/testing-node": "catalog:",
"@types/node": "catalog:",
"@types/pg": "catalog:",
"drizzle-kit": "1.0.0-beta.22",
Expand All @@ -99,6 +100,7 @@
},
"dependencies": {
"@electric-sql/pglite": "catalog:",
"@logtape/logtape": "catalog:",
"drizzle-orm": "catalog:",
"pg": "catalog:"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/email.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { normalizeEmail } from "@drfed/models/email";
import { describe, it } from "@logtape/testing-node/autoload";

describe("normalizeEmail()", () => {
it("with valid email", () => {
Expand Down
Loading
Loading