runtime-reporter 0.4.4 → 0.4.5
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 +78 -80
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,36 +1,92 @@
|
|
|
1
1
|
# Runtime Reporter
|
|
2
2
|
|
|
3
|
-
Structured runtime reporting that is type-safe, centralized, and production-ready — for frameworks and applications
|
|
3
|
+
Structured runtime reporting that is type-safe, centralized, and production-ready — for front-end frameworks and applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Runtime Reporter replaces ad-hoc logging with structured, code-based messaging.
|
|
6
|
+
|
|
7
|
+
## Why?
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
Runtime Reporter solves these problems:
|
|
8
10
|
|
|
9
11
|
- duplicated log messages
|
|
10
12
|
- inconsistent error wording
|
|
11
13
|
- fragile test assertions
|
|
12
14
|
- accidental exposure of sensitive data
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
by introducing these features:
|
|
17
|
+
|
|
18
|
+
- centralized and standardized error messaging
|
|
19
|
+
- stable error codes for debugging and error tracking
|
|
20
|
+
- test assertions without string duplication
|
|
21
|
+
- safer production output (no sensitive data exposure)
|
|
22
|
+
|
|
23
|
+
in a lightweight, self-contained package (less than 1 KB).
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install runtime-reporter
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
A copy-and-paste example of how to use Runtime Reporter in your project.
|
|
15
34
|
|
|
16
|
-
|
|
35
|
+
```ts
|
|
36
|
+
// src/runtime-reporter.ts
|
|
17
37
|
|
|
18
|
-
|
|
38
|
+
import { createReporter, type RuntimeReporterMessages } from "runtime-reporter";
|
|
19
39
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
const messages: RuntimeReporterMessages<
|
|
41
|
+
| {
|
|
42
|
+
code: "ERR01";
|
|
43
|
+
template: "{{ componentName }} failed to mount";
|
|
44
|
+
tokens: "componentName";
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
code: "ERR02";
|
|
48
|
+
template: "Failed to load configuration";
|
|
49
|
+
}
|
|
50
|
+
| {
|
|
51
|
+
code: "ERR03";
|
|
52
|
+
template: "Failed to fetch {{ resource }} from {{ url }}";
|
|
53
|
+
tokens: "resource" | "url";
|
|
54
|
+
}
|
|
55
|
+
> = {
|
|
56
|
+
ERR01: "{{ componentName }} failed to mount",
|
|
57
|
+
ERR02: "Failed to load configuration",
|
|
58
|
+
ERR03: "Failed to fetch {{ resource }} from {{ url }}",
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** The runtime reporter for <project-name> */
|
|
62
|
+
const reporter = createReporter(messages);
|
|
63
|
+
|
|
64
|
+
export default reporter;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Once your reporter is created, import and use it wherever you want:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// src/my-component.ts
|
|
71
|
+
|
|
72
|
+
import { reporter } from "./runtime-reporter";
|
|
73
|
+
|
|
74
|
+
export function MyComponent() {
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
reporter.error("ERR01", { componentName: "MyComponent" });
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
return <div>My Component</div>;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
26
82
|
|
|
27
83
|
## Features
|
|
28
84
|
|
|
29
|
-
If you are new to Runtime Reporter, take a moment to explore
|
|
85
|
+
If you are new to Runtime Reporter, take a moment to explore its core features.
|
|
30
86
|
|
|
31
|
-
### Basic usage
|
|
87
|
+
### 1. Basic usage
|
|
32
88
|
|
|
33
|
-
|
|
89
|
+
Create a reporter instance with your messages and start logging.
|
|
34
90
|
|
|
35
91
|
```ts
|
|
36
92
|
import { createReporter } from "runtime-reporter";
|
|
@@ -42,7 +98,7 @@ const reporter = createReporter({
|
|
|
42
98
|
reporter.error("ERR01");
|
|
43
99
|
```
|
|
44
100
|
|
|
45
|
-
### Code-based messaging
|
|
101
|
+
### 2. Code-based messaging
|
|
46
102
|
|
|
47
103
|
Replace inline strings with centralized, code-based identifiers.
|
|
48
104
|
|
|
@@ -54,7 +110,7 @@ console.error("MyComponent failed to mount");
|
|
|
54
110
|
reporter.error("ERR01");
|
|
55
111
|
```
|
|
56
112
|
|
|
57
|
-
### Dynamic messages
|
|
113
|
+
### 3. Dynamic messages
|
|
58
114
|
|
|
59
115
|
Inject runtime data into your messages via message templates and tokenized variables.
|
|
60
116
|
|
|
@@ -66,7 +122,7 @@ const reporter = createReporter({
|
|
|
66
122
|
reporter.error("ERR01", { componentName: "MyComponent" });
|
|
67
123
|
```
|
|
68
124
|
|
|
69
|
-
### Type safety
|
|
125
|
+
### 4. Type safety
|
|
70
126
|
|
|
71
127
|
Annotate your messages to get autocomplete and compile-time validation for message codes and token names.
|
|
72
128
|
|
|
@@ -91,7 +147,7 @@ reporter.error("ERR02", { componentName: "MyComponent" });
|
|
|
91
147
|
reporter.error("ERR01");
|
|
92
148
|
```
|
|
93
149
|
|
|
94
|
-
### Production environments
|
|
150
|
+
### 5. Production environments
|
|
95
151
|
|
|
96
152
|
Pass an empty object to the `createReporter` function in production environments for better security and a smaller bundle size.
|
|
97
153
|
|
|
@@ -101,7 +157,7 @@ const reporter = createReporter(
|
|
|
101
157
|
);
|
|
102
158
|
```
|
|
103
159
|
|
|
104
|
-
### Test friendly
|
|
160
|
+
### 6. Test friendly
|
|
105
161
|
|
|
106
162
|
Assert against resolved messages without duplicating message text in your test environment.
|
|
107
163
|
|
|
@@ -117,69 +173,11 @@ it("should log error if component fails to mount", () => {
|
|
|
117
173
|
});
|
|
118
174
|
```
|
|
119
175
|
|
|
120
|
-
## Installation
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
npm install runtime-reporter
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Quick start
|
|
127
|
-
|
|
128
|
-
A copy-and-paste example of how to use Runtime Reporter in your project.
|
|
129
|
-
|
|
130
|
-
```ts
|
|
131
|
-
// src/runtime-reporter.ts
|
|
132
|
-
|
|
133
|
-
import { createReporter, type RuntimeReporterMessages } from "runtime-reporter";
|
|
134
|
-
|
|
135
|
-
const messages: RuntimeReporterMessages<
|
|
136
|
-
| {
|
|
137
|
-
code: "ERR01";
|
|
138
|
-
template: "{{ componentName }} failed to mount";
|
|
139
|
-
tokens: "componentName";
|
|
140
|
-
}
|
|
141
|
-
| {
|
|
142
|
-
code: "ERR02";
|
|
143
|
-
template: "Failed to load configuration";
|
|
144
|
-
}
|
|
145
|
-
| {
|
|
146
|
-
code: "ERR03";
|
|
147
|
-
template: "Failed to fetch {{ resource }} from {{ url }}";
|
|
148
|
-
tokens: "resource" | "url";
|
|
149
|
-
}
|
|
150
|
-
> = {
|
|
151
|
-
ERR01: "{{ componentName }} failed to mount",
|
|
152
|
-
ERR02: "Failed to load configuration",
|
|
153
|
-
ERR03: "Failed to fetch {{ resource }} from {{ url }}",
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/** The runtime reporter for <project-name> */
|
|
157
|
-
const reporter = createReporter(messages);
|
|
158
|
-
|
|
159
|
-
export default reporter;
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Once your project's reporter is created, you can import and use it wherever you need it like this:
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
// src/my-component.ts
|
|
166
|
-
|
|
167
|
-
import { reporter } from "./runtime-reporter";
|
|
168
|
-
|
|
169
|
-
export function MyComponent() {
|
|
170
|
-
useEffect(() => {
|
|
171
|
-
reporter.error("ERR01", { componentName: "MyComponent" });
|
|
172
|
-
}, []);
|
|
173
|
-
|
|
174
|
-
return <div>My Component</div>;
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
176
|
## API
|
|
179
177
|
|
|
180
178
|
### `createReporter(RuntimeReporterMessages, options?: RuntimeReporterOptions): RuntimeReporter`
|
|
181
179
|
|
|
182
|
-
Takes a
|
|
180
|
+
Takes a messages object, an optional set of configuration options, and returns a reporter object.
|
|
183
181
|
|
|
184
182
|
### `RuntimeReporter`
|
|
185
183
|
|
|
@@ -268,7 +266,7 @@ You can still get the same benefits as TypeScript by using JSDoc-style type anno
|
|
|
268
266
|
* }>}
|
|
269
267
|
*/
|
|
270
268
|
const messages = {
|
|
271
|
-
ERR01: "{{ componentName }} failed
|
|
269
|
+
ERR01: "{{ componentName }} failed to mount",
|
|
272
270
|
ERR02: "Failed to load configuration",
|
|
273
271
|
ERR03: "Failed to fetch {{ resource }} from {{ url }}",
|
|
274
272
|
};
|