From 2782b56627dde6a31b32e17499a0cdd6b5a8b83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20P=C3=A9rez?= Date: Wed, 3 Apr 2024 18:47:39 -0600 Subject: [PATCH 1/2] added TS types --- package.json | 2 ++ types/index.d.ts | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 types/index.d.ts diff --git a/package.json b/package.json index 7f09b5c..2a5b9cd 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,10 @@ "journald" ], "author": "Jue ", + "contributors": ["Mikel PĂ©rez "], "license": "MIT", "main": "index.js", + "types": "types/index.d.ts", "repository": { "type": "git", "url": "https://github.com/jue89/node-systemd-journald.git" diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..d910977 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,42 @@ +declare module "systemd-journald" { + // https://man7.org/linux/man-pages/man7/systemd.journal-fields.7.html + export type JournalFields = { + message_id?: string, + code_file?: string, + code_line?: string, + code_func?: string, + errno?: string, + invocation_id?: string, + user_invocation_id?: string, + syslog_facility?: string, + syslog_identifier?: string, + syslog_pid?: string, + syslog_timestamp?: string, + syslog_raw?: string, + documentation?: string, + tid?: string, + unit?: string, + user_unit?: string + } + + export default class systemd_journald { + constructor(defaultFields: JournalFields); + + alert(message: string, fields?: JournalFields): void; + crit(message: string, fields?: JournalFields): void; + debug(message: string, fields?: JournalFields): void; + emerg(message: string, fields?: JournalFields): void; + err(message: string, fields?: JournalFields): void; + info(message: string, fields?: JournalFields): void; + notice(message: string, fields?: JournalFields): void; + warning(message: string, fields?: JournalFields): void; + static alert(message: string, fields?: JournalFields): void; + static crit(message: string, fields?: JournalFields): void; + static debug(message: string, fields?: JournalFields): void; + static emerg(message: string, fields?: JournalFields): void; + static err(message: string, fields?: JournalFields): void; + static info(message: string, fields?: JournalFields): void; + static notice(message: string, fields?: JournalFields): void; + static warning(message: string, fields?: JournalFields): void; + } +} From 40e707329221fd015d676da7e806ab24f966bfc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20P=C3=A9rez?= Date: Sat, 6 Apr 2024 13:14:37 -0600 Subject: [PATCH 2/2] allow custom fields --- types/index.d.ts | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index d910977..16b22b0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,23 +1,24 @@ -declare module "systemd-journald" { +declare module 'systemd-journald' { // https://man7.org/linux/man-pages/man7/systemd.journal-fields.7.html - export type JournalFields = { - message_id?: string, - code_file?: string, - code_line?: string, - code_func?: string, - errno?: string, - invocation_id?: string, - user_invocation_id?: string, - syslog_facility?: string, - syslog_identifier?: string, - syslog_pid?: string, - syslog_timestamp?: string, - syslog_raw?: string, - documentation?: string, - tid?: string, - unit?: string, - user_unit?: string - } + export type JournalFields = Partial<{ + message_id: string, + code_file: string, + code_line: string, + code_func: string, + errno: string, + invocation_id: string, + user_invocation_id: string, + syslog_facility: string, + syslog_identifier: string, + syslog_pid: string, + syslog_timestamp: string, + syslog_raw: string, + documentation: string, + tid: string, + unit: string, + user_unit: string, + [custom_field: string]: string + }> export default class systemd_journald { constructor(defaultFields: JournalFields);