Skip to content

Commit

Permalink
move from old deps.ts style to import maps in deno.jsonc
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrie158 committed Sep 20, 2024
1 parent 4858344 commit 09b83df
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 58 deletions.
2 changes: 1 addition & 1 deletion configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as log from "@std/log";
import { CheckedConfiguration, ConfigOption, EnvironmentConfiguration } from "./lib/env.ts";
import { log } from "./deps.ts";
import { CONTAINER_ACTIONS, ContainerAction } from "./lib/docker-api.ts";

const SUPERVISION_MODES = ["TAGGED", "UNTAGGED", "PREFIXED", "NOTPREFIXED", "ALL"] as const;
Expand Down
14 changes: 14 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,19 @@
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"imports": {
"@std/io": "jsr:@std/[email protected]",
"@std/log": "jsr:@std/[email protected]",
"@std/front-matter": "jsr:@std/[email protected]",
"@std/path": "jsr:@std/[email protected]",
"@std/async": "jsr:@std/[email protected]",
"@std/streams": "jsr:@std/[email protected]",
"@std/ulid": "jsr:@std/[email protected]",
"@dx/reflect": "jsr:@dx/[email protected]",
"eta": "https://deno.land/x/[email protected]/src/index.ts",
"eta/file-handling": "https://deno.land/x/[email protected]/src/file-handling.ts",
"@b-fuze/deno-dom": "jsr:@b-fuze/[email protected]",
"deno-smtp": "https://deno.land/x/[email protected]/mod.ts"
}
}
18 changes: 0 additions & 18 deletions deps.ts

This file was deleted.

8 changes: 4 additions & 4 deletions docs/advanced/custom-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ For `restart` templates the context additionally contains the following properti
| `downtime_end` | `Date` | Timestamp at which Dolce started again |

[^1]: [`DockerContainerEvent`](https://github.com/dangrie158/dolce/blob/master/lib/event_registry.ts#L4) and
[`DockerApiContainerEvent`](https://github.com/dangrie158/dolce/blob/master/lib/docker-api.ts#L86)
[`DockerApiContainerEvent`](https://github.com/dangrie158/dolce/blob/master/lib/docker-api.ts#L86)

### Helper Functions

Expand Down Expand Up @@ -133,9 +133,9 @@ action:
| `die` | ❌ |
| `kill` | ❌ |
| `oom` | ❌ |
| `stop` | ⏹️ |
| `pause` | ⏸️ |
| `unpause` | ⏯️ |
| `stop` | ⏹️ |
| `pause` | ⏸️ |
| `unpause` | ⏯️ |
| `health_status` | ❓ |

Example usage:
Expand Down
8 changes: 4 additions & 4 deletions lib/async.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { async } from "../deps.ts";
import { deadline } from "@std/async";

export function wait(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand Down Expand Up @@ -33,15 +33,15 @@ export function throttle<T extends Array<void>>(

export function DeadlinedReader<T>(
reader: ReadableStreamDefaultReader<T>,
deadline: number,
timeout: number,
): ReadableStreamDefaultReader<T> {
return {
...reader,
read: async () => {
try {
return await async.deadline(reader.read(), deadline);
return await deadline(reader.read(), timeout);
} catch (error) {
if (error instanceof async.DeadlineError) {
if (error instanceof DOMException && error.name === "TimeoutError") {
reader.cancel();
return { done: true, value: undefined };
}
Expand Down
2 changes: 1 addition & 1 deletion lib/docker-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextLineStream } from "../deps.ts";
import { TextLineStream } from "@std/streams";
import { DeadlinedReader } from "./async.ts";
import { HttpSocket } from "./universal-http.ts";

Expand Down
2 changes: 1 addition & 1 deletion lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReflectMetadata } from "../deps.ts";
import { Reflect as ReflectMetadata } from "@dx/reflect";
/**
* Convenience functions to get values from the environment in the requestst type
* with a defaultvalue as fallback
Expand Down
5 changes: 3 additions & 2 deletions lib/event_registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ulid } from "@std/ulid";
import { join as join_path } from "@std/path";
import { DockerApiContainerEvent } from "./docker-api.ts";
import { path, ulid } from "../deps.ts";

type DockerContainerEvent = DockerApiContainerEvent & {
actor_name: string;
Expand Down Expand Up @@ -38,7 +39,7 @@ export async function register(
delivery_callback: DeliveryCallback,
backoff_settings: BackoffSettings,
): Promise<EventRegistry> {
const db_path = path.join(run_directory, "dolce.db");
const db_path = join_path(run_directory, "dolce.db");
const db = await Deno.openKv(db_path);
const registry: EventRegistry = { db, backoff_settings };

Expand Down
5 changes: 3 additions & 2 deletions lib/lockfile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { log, path } from "../deps.ts";
import { getLogger } from "@std/log";
import * as path from "@std/path";
import { throttle } from "./async.ts";

type LockFileInformation = {
Expand All @@ -20,7 +21,7 @@ export enum LockFileRegisterStatus {
export class LockFile {
static UPDATE_THROTTLE_INTERVAL = 1000;
static get logger() {
return log.getLogger("lockfile");
return getLogger("lockfile");
}

private lock_file_path: string;
Expand Down
35 changes: 16 additions & 19 deletions lib/notifiers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { log, SmtpClient } from "../deps.ts";
import { SmtpClient } from "deno-smtp";
import { getLogger } from "@std/log";
import { DockerApiContainerEvent } from "./docker-api.ts";
import { CheckedConfiguration, ConfigOption, EnvironmentConfiguration } from "./env.ts";
import {
Expand Down Expand Up @@ -38,7 +39,7 @@ export abstract class Notifier {
protected abstract send_message(_message: Template): Promise<void>;

public static get logger() {
return log.getLogger("notifier");
return getLogger("notifier");
}
}

Expand Down Expand Up @@ -172,18 +173,19 @@ class TelegramNotifier extends Notifier {
static message_class = TelegramTemplate;

protected async send_message(message: TelegramTemplate) {
const send_promises = TelegramNotifier.config.recipient_ids.map(async (recipient) =>
await fetch(`https://api.telegram.org/bot${TelegramNotifier.config.http_token!}/sendMessage`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
chat_id: recipient,
text: message.text,
parse_mode: "MarkdownV2",
const send_promises = TelegramNotifier.config.recipient_ids.map(
async (recipient) =>
await fetch(`https://api.telegram.org/bot${TelegramNotifier.config.http_token!}/sendMessage`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
chat_id: recipient,
text: message.text,
parse_mode: "MarkdownV2",
}),
}),
})
);
await Promise.all(send_promises);
}
Expand Down Expand Up @@ -253,9 +255,4 @@ export function try_create(
notifier_class.logger.info(`creating ${notifier_class.name}`);
return new notifier_class(notifier_class.message_class, hostname);
}
export const ALL_NOTIFIERS: ConcreteNotifier[] = [
SmtpNotifier,
DiscordNotifier,
TelegramNotifier,
AppriseNotifier,
];
export const ALL_NOTIFIERS: ConcreteNotifier[] = [SmtpNotifier, DiscordNotifier, TelegramNotifier, AppriseNotifier];
10 changes: 7 additions & 3 deletions lib/templates.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { DOMParser, Eta, EtaOptions, extract_frontmatter, path, resolve_template_path } from "../deps.ts";
import * as front_matter from "@std/front-matter";
import * as path from "@std/path";
import { DOMParser } from "@b-fuze/deno-dom";
import { Eta, type Options as EtaOptions } from "eta";
import { DockerApiContainerEvent } from "./docker-api.ts";
import { Configuration } from "../configuration.ts";
import { resolvePath as resolve_template_path } from "eta/file-handling";
export type EventTemplateName = "event.eta" | "restart.eta";

export type BaseMessageContext = {
Expand Down Expand Up @@ -172,7 +176,7 @@ export class EMailTemplate extends Template {
async render(context: MessageContext) {
const template_path = this.path;
const template_contents = await Deno.readTextFile(template_path);
const { attrs, body } = extract_frontmatter<EMailFrontMatter>(template_contents);
const { attrs, body } = front_matter.extractJson<EMailFrontMatter>(template_contents);
this.frontmatter = attrs;
this.html_content = await this.engine.renderStringAsync(body, {
...context,
Expand Down Expand Up @@ -230,7 +234,7 @@ export class AppriseTemplate extends Template {
async render(context: MessageContext) {
const template_path = this.path;
const template_contents = await Deno.readTextFile(template_path);
const { attrs, body } = extract_frontmatter<AppriseFrontMatter>(template_contents);
const { attrs, body } = front_matter.extractJson<AppriseFrontMatter>(template_contents);
this.frontmatter = attrs;
this.text_content = await this.engine.renderStringAsync(body, {
...context,
Expand Down
2 changes: 1 addition & 1 deletion lib/universal-http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DelimiterStream } from "../deps.ts";
import { DelimiterStream } from "@std/streams";

const UA_VERSION = "2.10.9";
const UA_STRING = `Dolce Container Monitor v${UA_VERSION}`;
Expand Down
2 changes: 1 addition & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { log } from "./deps.ts";
import * as log from "@std/log";

import { DockerApi, DockerApiContainerEvent, DockerApiEvent, DockerApiEventFilters } from "./lib/docker-api.ts";
import { LockFile, LockFileRegisterStatus } from "./lib/lockfile.ts";
Expand Down
2 changes: 1 addition & 1 deletion test/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TelegramTemplate,
} from "../lib/templates.ts";
import { assert, assertStrictEquals, assertThrows } from "https://deno.land/[email protected]/assert/mod.ts";
import { path } from "../deps.ts";
import * as path from "@std/path";

const dummy_render_context: RestartMessageContext = {
downtime_start: new Date(),
Expand Down

0 comments on commit 09b83df

Please sign in to comment.