Halkyon's shared packages
A pub workspace of the Dart packages Halkyon's apps share: halkyon_ui, Halkyon's look (the theme, fonts, layout and shared widgets, with texts in English and German), halkyon_core's low-level primitives and halkyon_interop's cross-app contracts. Dart 3.13 with LeanCode's lints, configured once at the root; apps take a package by git, pinned to a signed commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
commit
80fa7b9628
3 changed files with 6762 additions and 0 deletions
11
packages/halkyon_core/lib/src/exceptions.dart
Normal file
11
packages/halkyon_core/lib/src/exceptions.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/// Marker interface for exceptions originating in Halkyon code.
|
||||
///
|
||||
/// Implementing this is optional. It exists so callers can distinguish
|
||||
/// "this came from Halkyon" from "this came from a library we use" using
|
||||
/// `on HalkyonException catch (e)` if they want that granularity.
|
||||
///
|
||||
/// Most Halkyon exceptions should also extend a more specific type
|
||||
/// (e.g., `AuthException`, `SyncException`) defined in the relevant feature.
|
||||
abstract class HalkyonException() implements Exception {
|
||||
String get message;
|
||||
}
|
||||
54
packages/halkyon_core/lib/src/logger.dart
Normal file
54
packages/halkyon_core/lib/src/logger.dart
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/// Severity levels for log messages.
|
||||
enum LogLevel() {
|
||||
debug,
|
||||
info,
|
||||
warning,
|
||||
error,
|
||||
}
|
||||
|
||||
/// A minimal logging interface.
|
||||
///
|
||||
/// Implementations are injected via the app's `Dependencies` composition root
|
||||
/// rather than imported globally, so tests can swap in fakes.
|
||||
abstract interface class Logger() {
|
||||
void log(
|
||||
LogLevel level,
|
||||
String message, {
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
});
|
||||
}
|
||||
|
||||
/// A logger that writes to stdout. Suitable for development and tests.
|
||||
///
|
||||
/// Production apps should use a logger that forwards to Sentry or similar,
|
||||
/// configured at the composition root.
|
||||
class const ConsoleLogger() implements Logger {
|
||||
@override
|
||||
void log(
|
||||
LogLevel level,
|
||||
String message, {
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
}) {
|
||||
final prefix = switch (level) {
|
||||
LogLevel.debug => '[DEBUG]',
|
||||
LogLevel.info => '[INFO]',
|
||||
LogLevel.warning => '[WARN]',
|
||||
LogLevel.error => '[ERROR]',
|
||||
};
|
||||
// Writing to stdout is this logger's whole purpose.
|
||||
// ignore: avoid_print
|
||||
print('$prefix $message');
|
||||
if (error != null) {
|
||||
// As above: stdout is where this logger writes.
|
||||
// ignore: avoid_print
|
||||
print(' error: $error');
|
||||
}
|
||||
if (stackTrace != null) {
|
||||
// As above: stdout is where this logger writes.
|
||||
// ignore: avoid_print
|
||||
print(' stack: $stackTrace');
|
||||
}
|
||||
}
|
||||
}
|
||||
10
packages/halkyon_core/lib/src/uuid.dart
Normal file
10
packages/halkyon_core/lib/src/uuid.dart
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import 'package:uuid/uuid.dart';
|
||||
|
||||
const _uuid = Uuid();
|
||||
|
||||
/// Generates a v4 (random) UUID as a lowercase hyphenated string.
|
||||
///
|
||||
/// Thin wrapper over `package:uuid` so Halkyon code doesn't need to import
|
||||
/// it directly. If we ever need to swap the UUID library, this is the only
|
||||
/// site that changes.
|
||||
String generateUuid() => _uuid.v4();
|
||||
Reference in a new issue