@awarded/log4brains-core 0.0.0-stage → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # @awarded/log4brains-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package provides the core API of the [Log4brains](https://github.com/FreakinWard/log4brains) architecture knowledge base.
4
+ It is not meant to be used directly.
5
+
6
+ Install [the main log4brains package](https://www.npmjs.com/package/log4brains) instead:
7
+
8
+ ```bash
9
+ npm install -g @awarded/log4brains
10
+ ```
11
+
12
+ ## Installation
13
+
14
+ This package is not meant to be installed directly in your project.
15
+
16
+ However, if you want to create a package that uses [Log4brains](https://github.com/FreakinWard/log4brains)' API,
17
+ you can include this package as a dependency:
18
+
19
+ ```bash
20
+ npm install --save @awarded/log4brains-core
21
+ ```
22
+
23
+ or
24
+
25
+ ```bash
26
+ yarn add @awarded/log4brains-core
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```typescript
32
+ import { Log4brains } from "@awarded/log4brains-core";
33
+
34
+ const l4b = Log4brains.createFromCwd(process.cwd());
35
+
36
+ // See the TypeDoc documentation (TODO: to deploy on GitHub pages) to see available API methods
37
+ ```
38
+
39
+ ## Documentation
40
+
41
+ - TypeDoc documentation (TODO)
42
+ - [Log4brains README](https://github.com/FreakinWard/log4brains/blob/develop/README.md)
@@ -0,0 +1,212 @@
1
+ type ProjectPackageConfig = Readonly<{
2
+ name: string;
3
+ path: string;
4
+ adrFolder: string;
5
+ }>;
6
+ declare const gitProviders: readonly ["github", "gitlab", "bitbucket", "generic"];
7
+ type GitProvider = (typeof gitProviders)[number];
8
+ type GitRepositoryConfig = Readonly<{
9
+ url?: string;
10
+ provider?: GitProvider;
11
+ viewFileUriPattern?: string;
12
+ }>;
13
+ type ProjectConfig = Readonly<{
14
+ name: string;
15
+ tz: string;
16
+ adrFolder: string;
17
+ packages?: ProjectPackageConfig[];
18
+ repository?: GitRepositoryConfig;
19
+ }>;
20
+ type Log4brainsConfig = Readonly<{
21
+ project: ProjectConfig;
22
+ }>;
23
+
24
+ /**
25
+ * Log4brains Error base class.
26
+ * Any error thrown by the core API extends this class.
27
+ */
28
+ declare class Log4brainsError extends Error {
29
+ readonly name: string;
30
+ readonly details?: string | undefined;
31
+ constructor(name: string, details?: string | undefined);
32
+ }
33
+
34
+ declare class Log4brainsConfigNotFoundError extends Log4brainsError {
35
+ constructor();
36
+ }
37
+
38
+ type AdrDtoStatus = "draft" | "proposed" | "rejected" | "accepted" | "deprecated" | "superseded";
39
+ type AdrDto = Readonly<{
40
+ slug: string;
41
+ package: string | null;
42
+ title: string | null;
43
+ status: AdrDtoStatus;
44
+ supersededBy: string | null;
45
+ tags: string[];
46
+ deciders: string[];
47
+ body: Readonly<{
48
+ rawMarkdown: string;
49
+ enhancedMdx: string;
50
+ }>;
51
+ creationDate: string;
52
+ lastEditDate: string;
53
+ lastEditAuthor: string;
54
+ publicationDate: string | null;
55
+ file: Readonly<{
56
+ relativePath: string;
57
+ absolutePath: string;
58
+ }>;
59
+ repository?: Readonly<{
60
+ provider: GitProvider;
61
+ viewUrl: string;
62
+ }>;
63
+ }>;
64
+
65
+ declare const fileWatcherEventTypes: readonly ["add", "addDir", "change", "unlink", "unlinkDir"];
66
+ type FileWatcherEventType = (typeof fileWatcherEventTypes)[number];
67
+ type FileWatcherEvent = {
68
+ type: FileWatcherEventType;
69
+ relativePath: string;
70
+ };
71
+ type FileWatcherObserver = (event: FileWatcherEvent) => void;
72
+ type FileWatcherUnsubscribeCb = () => void;
73
+ type Deps = {
74
+ config: Log4brainsConfig;
75
+ workdir: string;
76
+ };
77
+ /**
78
+ * Watch files located in the main ADR folder, and in each package's ADR folder.
79
+ * Useful for Hot Reloading.
80
+ * The caller is responsible for starting and stopping it!
81
+ */
82
+ declare class FileWatcher {
83
+ private readonly config;
84
+ private readonly workdir;
85
+ private chokidar;
86
+ private observers;
87
+ constructor({ config, workdir }: Deps);
88
+ subscribe(cb: FileWatcherObserver): FileWatcherUnsubscribeCb;
89
+ start(): void;
90
+ stop(): Promise<void>;
91
+ }
92
+
93
+ type SearchAdrsFilters = {
94
+ statuses?: AdrDtoStatus[];
95
+ };
96
+ /**
97
+ * Log4brains core API.
98
+ * Use {@link Log4brains.create} to build an instance.
99
+ */
100
+ declare class Log4brains {
101
+ readonly config: Log4brainsConfig;
102
+ readonly workdir: string;
103
+ private readonly container;
104
+ private readonly commandBus;
105
+ private readonly queryBus;
106
+ private readonly adrRepository;
107
+ private constructor();
108
+ /**
109
+ * Returns the ADRs which match the given search filters.
110
+ * Returns all the ADRs of the project if no filter is given.
111
+ * The results are sorted with this order priority (ASC):
112
+ * 1. By the Date field from the markdown file (if available)
113
+ * 2. By the Git creation date (does not follow renames)
114
+ * 3. By slug
115
+ *
116
+ * @param filters Optional. Filters to apply to the search
117
+ *
118
+ * @throws {@link Log4brainsError}
119
+ * In case of a non-recoverable error.
120
+ */
121
+ searchAdrs(filters?: SearchAdrsFilters): Promise<AdrDto[]>;
122
+ /**
123
+ * Returns an ADR by its slug.
124
+ *
125
+ * @param slug ADR slug
126
+ *
127
+ * @throws {@link Log4brainsError}
128
+ * In case of a non-recoverable error.
129
+ */
130
+ getAdrBySlug(slug: string): Promise<AdrDto | undefined>;
131
+ /**
132
+ * Generates an available ADR slug for the given title and package.
133
+ * Format: [package-name/]yyyymmdd-slugified-lowercased-title
134
+ *
135
+ * @param title The title of the ADR
136
+ * @param packageName Optional. The package name of the ADR.
137
+ *
138
+ * @throws {@link Log4brainsError}
139
+ * In case of a non-recoverable error.
140
+ */
141
+ generateAdrSlug(title: string, packageName?: string): Promise<string>;
142
+ /**
143
+ * Creates a new ADR with the given slug and title with the default template.
144
+ * @param slug The slug of the ADR
145
+ * @param title The title of the ADR
146
+ *
147
+ * @throws {@link Log4brainsError}
148
+ * In case of a non-recoverable error.
149
+ */
150
+ createAdrFromTemplate(slug: string, title: string): Promise<AdrDto>;
151
+ /**
152
+ * Supersede an ADR with another one.
153
+ * @param supersededSlug Slug of the superseded ADR
154
+ * @param supersederSlug Slug of the superseder ADR
155
+ *
156
+ * @throws {@link Log4brainsError}
157
+ * In case of a non-recoverable error.
158
+ */
159
+ supersedeAdr(supersededSlug: string, supersederSlug: string): Promise<void>;
160
+ /**
161
+ * Opens the given ADR in an editor on the local machine.
162
+ * Tries first to guess the preferred editor of the user thanks to https://github.com/yyx990803/launch-editor.
163
+ * If impossible to guess, uses xdg-open (or similar, depending on the OS, thanks to https://github.com/sindresorhus/open) as a fallback.
164
+ * The overall order is thus the following:
165
+ * 1) The currently running editor among the supported ones by launch-editor
166
+ * 2) The editor defined by the $VISUAL environment variable
167
+ * 3) The editor defined by the $EDITOR environment variable
168
+ * 4) Fallback: xdg-open or similar
169
+ *
170
+ * @param slug The ADR slug to open
171
+ * @param onImpossibleToGuess Optional. Callback called when the fallback method is used.
172
+ * Useful to display a warning to the user to tell him to set his $VISUAL environment variable for the next time.
173
+ *
174
+ * @throws {@link Log4brainsError}
175
+ * If the ADR does not exist or if even the fallback method fails.
176
+ */
177
+ openAdrInEditor(slug: string, onImpossibleToGuess?: () => void): Promise<void>;
178
+ /**
179
+ * Returns a singleton instance of FileWatcher.
180
+ * Useful for Hot Reloading.
181
+ * @see FileWatcher
182
+ */
183
+ get fileWatcher(): FileWatcher;
184
+ /**
185
+ * Creates an instance of the Log4brains API.
186
+ *
187
+ * @param workdir Path to working directory (ie. where ".log4brains.yml" is located)
188
+ *
189
+ * @throws {@link Log4brainsConfigNotFoundError}
190
+ * In case of missing config file.
191
+ *
192
+ * @throws {@link Log4brainsError}
193
+ * In case of invalid config file or other domain error.
194
+ */
195
+ static create(workdir?: string): Log4brains;
196
+ /**
197
+ * Creates an instance of the Log4brains API from a working directory.
198
+ * The real working directory (ie. where ".log4brains.yml" is located) will be guessed looking in the parent directories.
199
+ *
200
+ * @param cwd Current working directory
201
+ *
202
+ * @throws {@link Log4brainsConfigNotFoundError}
203
+ * In case of missing config file.
204
+ *
205
+ * @throws {@link Log4brainsError}
206
+ * In case of invalid config file or other domain error.
207
+ */
208
+ static createFromCwd(cwd?: string): Log4brains;
209
+ }
210
+
211
+ export { FileWatcher, Log4brains, Log4brainsConfigNotFoundError, Log4brainsError };
212
+ export type { AdrDto, AdrDtoStatus, FileWatcherEvent, FileWatcherEventType, FileWatcherObserver, FileWatcherUnsubscribeCb, Log4brainsConfig, SearchAdrsFilters };