shelving 1.197.0 → 1.199.0
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/api/index.d.ts +1 -0
- package/api/index.js +1 -0
- package/api/provider/CachedAPIProvider.d.ts +20 -0
- package/api/provider/CachedAPIProvider.js +34 -0
- package/api/provider/DebugAPIProvider.d.ts +1 -1
- package/api/provider/DebugAPIProvider.js +10 -14
- package/api/provider/LoggingAPIProvider.d.ts +20 -0
- package/api/provider/LoggingAPIProvider.js +35 -0
- package/db/provider/DebugDBProvider.js +39 -38
- package/package.json +1 -1
- package/util/ansi.d.ts +5 -0
- package/util/ansi.js +6 -0
- package/util/log.d.ts +7 -0
- package/util/log.js +15 -0
package/api/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./cache/EndpointCache.js";
|
|
|
3
3
|
export * from "./endpoint/Endpoint.js";
|
|
4
4
|
export * from "./endpoint/util.js";
|
|
5
5
|
export * from "./provider/APIProvider.js";
|
|
6
|
+
export * from "./provider/CachedAPIProvider.js";
|
|
6
7
|
export * from "./provider/ClientAPIProvider.js";
|
|
7
8
|
export * from "./provider/DebugAPIProvider.js";
|
|
8
9
|
export * from "./provider/JSONAPIProvider.js";
|
package/api/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./cache/EndpointCache.js";
|
|
|
3
3
|
export * from "./endpoint/Endpoint.js";
|
|
4
4
|
export * from "./endpoint/util.js";
|
|
5
5
|
export * from "./provider/APIProvider.js";
|
|
6
|
+
export * from "./provider/CachedAPIProvider.js";
|
|
6
7
|
export * from "./provider/ClientAPIProvider.js";
|
|
7
8
|
export * from "./provider/DebugAPIProvider.js";
|
|
8
9
|
export * from "./provider/JSONAPIProvider.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnyCaller } from "../../util/function.js";
|
|
2
|
+
import type { Endpoint } from "../endpoint/Endpoint.js";
|
|
3
|
+
import type { APIProvider } from "./APIProvider.js";
|
|
4
|
+
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
5
|
+
/**
|
|
6
|
+
* API provider wrapper that serves requests through an `APICache`.
|
|
7
|
+
* - Constructor accepts a `source` provider and an optional default `maxAge`.
|
|
8
|
+
* - On `call(...)`, triggers `cache.refresh(maxAge)` for the endpoint+payload before awaiting `cache.call(...)`.
|
|
9
|
+
* - `invalidate`, `invalidateAll`, `refresh`, and `refreshAll` pass through to the underlying cache and use `this.maxAge` as the default refresh timing.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CachedAPIProvider<P, R> extends ThroughAPIProvider<P, R> {
|
|
12
|
+
readonly maxAge: number | undefined;
|
|
13
|
+
private readonly _cache;
|
|
14
|
+
constructor(source: APIProvider<P, R>, maxAge?: number);
|
|
15
|
+
call<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, maxAge?: number | undefined, caller?: AnyCaller): Promise<RR>;
|
|
16
|
+
invalidate<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP): void;
|
|
17
|
+
invalidateAll<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>): void;
|
|
18
|
+
refresh<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP): void;
|
|
19
|
+
refreshAll<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { APICache } from "../cache/APICache.js";
|
|
2
|
+
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
3
|
+
/**
|
|
4
|
+
* API provider wrapper that serves requests through an `APICache`.
|
|
5
|
+
* - Constructor accepts a `source` provider and an optional default `maxAge`.
|
|
6
|
+
* - On `call(...)`, triggers `cache.refresh(maxAge)` for the endpoint+payload before awaiting `cache.call(...)`.
|
|
7
|
+
* - `invalidate`, `invalidateAll`, `refresh`, and `refreshAll` pass through to the underlying cache and use `this.maxAge` as the default refresh timing.
|
|
8
|
+
*/
|
|
9
|
+
export class CachedAPIProvider extends ThroughAPIProvider {
|
|
10
|
+
maxAge;
|
|
11
|
+
_cache;
|
|
12
|
+
constructor(source, maxAge) {
|
|
13
|
+
super(source);
|
|
14
|
+
this.maxAge = maxAge;
|
|
15
|
+
this._cache = new APICache(source);
|
|
16
|
+
}
|
|
17
|
+
// @ts-expect-error TS2416: intentionally diverges from `APIProvider.call` — `RequestOptions` are not used by the cache, so the third arg is repurposed as `maxAge`.
|
|
18
|
+
call(endpoint, payload, maxAge = this.maxAge, caller = this.call) {
|
|
19
|
+
this._cache.refresh(endpoint, payload, maxAge);
|
|
20
|
+
return this._cache.call(endpoint, payload, maxAge, caller);
|
|
21
|
+
}
|
|
22
|
+
invalidate(endpoint, payload) {
|
|
23
|
+
this._cache.invalidate(endpoint, payload);
|
|
24
|
+
}
|
|
25
|
+
invalidateAll(endpoint) {
|
|
26
|
+
this._cache.invalidateAll(endpoint);
|
|
27
|
+
}
|
|
28
|
+
refresh(endpoint, payload) {
|
|
29
|
+
this._cache.refresh(endpoint, payload, this.maxAge);
|
|
30
|
+
}
|
|
31
|
+
refreshAll(endpoint) {
|
|
32
|
+
this._cache.refreshAll(endpoint, this.maxAge);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { AnyCaller } from "../../util/function.js";
|
|
|
2
2
|
import type { RequestOptions } from "../../util/http.js";
|
|
3
3
|
import type { Endpoint } from "../endpoint/Endpoint.js";
|
|
4
4
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
5
|
-
/** Provider that logs
|
|
5
|
+
/** Provider that logs everything to the console in some detail to help diagnose issues in development. */
|
|
6
6
|
export declare class DebugAPIProvider<P, R> extends ThroughAPIProvider<P, R> {
|
|
7
7
|
getRequest<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, options?: RequestOptions, caller?: AnyCaller): Request;
|
|
8
8
|
fetch(request: Request): Promise<Response>;
|
|
@@ -1,43 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ANSI_ICON_ERROR, ANSI_ICON_REQUEST, ANSI_ICON_RESPONSE, ANSI_ICON_SUCCESS, ANSI_ICON_WAITING } from "../../util/ansi.js";
|
|
2
|
+
import { debugFullRequest, debugFullResponse, debugRequest } from "../../util/debug.js";
|
|
2
3
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
3
|
-
/** Provider that logs
|
|
4
|
+
/** Provider that logs everything to the console in some detail to help diagnose issues in development. */
|
|
4
5
|
export class DebugAPIProvider extends ThroughAPIProvider {
|
|
5
6
|
getRequest(endpoint, payload, options, caller = this.getRequest) {
|
|
6
|
-
const url = this.url.toString();
|
|
7
|
-
const ep = endpoint.toString();
|
|
8
7
|
try {
|
|
9
8
|
const request = super.getRequest(endpoint, payload, options, caller);
|
|
10
|
-
console.debug(
|
|
9
|
+
console.debug(`${ANSI_ICON_WAITING} ${endpoint.toString()}`, payload);
|
|
11
10
|
return request;
|
|
12
11
|
}
|
|
13
12
|
catch (reason) {
|
|
14
|
-
console.error(
|
|
13
|
+
console.error(`${ANSI_ICON_ERROR} ${endpoint.toString()}`, payload, reason);
|
|
15
14
|
throw reason;
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
async fetch(request) {
|
|
19
|
-
const url = this.url.toString();
|
|
20
18
|
try {
|
|
21
|
-
console.debug(
|
|
19
|
+
console.debug(`${ANSI_ICON_REQUEST} ${await debugFullRequest(request)}`);
|
|
22
20
|
const response = await super.fetch(request);
|
|
23
|
-
console.debug(
|
|
21
|
+
console.debug(`${ANSI_ICON_RESPONSE} ${debugRequest(request)}\n\n${await debugFullResponse(response)}`);
|
|
24
22
|
return response;
|
|
25
23
|
}
|
|
26
24
|
catch (reason) {
|
|
27
|
-
console.error(
|
|
25
|
+
console.error(`${ANSI_ICON_ERROR} ${debugRequest(request)}`, reason);
|
|
28
26
|
throw reason;
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
29
|
async parseResponse(endpoint, response, caller = this.parseResponse) {
|
|
32
|
-
const url = this.url.toString();
|
|
33
|
-
const ep = endpoint.toString();
|
|
34
30
|
try {
|
|
35
31
|
const result = await super.parseResponse(endpoint, response, caller);
|
|
36
|
-
console.debug(
|
|
32
|
+
console.debug(`${ANSI_ICON_SUCCESS} ${endpoint.toString()}`, result);
|
|
37
33
|
return result;
|
|
38
34
|
}
|
|
39
35
|
catch (reason) {
|
|
40
|
-
console.error(
|
|
36
|
+
console.error(`${ANSI_ICON_ERROR} ${endpoint.toString()}`, reason);
|
|
41
37
|
throw reason;
|
|
42
38
|
}
|
|
43
39
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Callback } from "../../util/function.js";
|
|
2
|
+
import type { APIProvider } from "./APIProvider.js";
|
|
3
|
+
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Provider that logs fetches to the console to keep useful logs in production.
|
|
6
|
+
* - Defaults to calling `console.log()` for requests/responses and
|
|
7
|
+
*/
|
|
8
|
+
export declare class LoggingAPIProvider<P, R> extends ThroughAPIProvider<P, R> {
|
|
9
|
+
protected _logRequest: Callback<[Request]>;
|
|
10
|
+
protected _logResponse: Callback<[Response, Request]>;
|
|
11
|
+
protected _logError: Callback<[reason: unknown, Request]>;
|
|
12
|
+
constructor(source: APIProvider<P, R>,
|
|
13
|
+
/** Log requests. */
|
|
14
|
+
onRequest?: Callback<[Request]>,
|
|
15
|
+
/** Log responses to requests. */
|
|
16
|
+
onResponse?: Callback<[Response, Request]>,
|
|
17
|
+
/** Log errors for requests. */
|
|
18
|
+
onError?: Callback<[reason: unknown, Request]>);
|
|
19
|
+
fetch(request: Request): Promise<Response>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { logRequest, logRequestError, logRequestResponse } from "../../util/log.js";
|
|
2
|
+
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Provider that logs fetches to the console to keep useful logs in production.
|
|
5
|
+
* - Defaults to calling `console.log()` for requests/responses and
|
|
6
|
+
*/
|
|
7
|
+
export class LoggingAPIProvider extends ThroughAPIProvider {
|
|
8
|
+
_logRequest;
|
|
9
|
+
_logResponse;
|
|
10
|
+
_logError;
|
|
11
|
+
constructor(source,
|
|
12
|
+
/** Log requests. */
|
|
13
|
+
onRequest = logRequest,
|
|
14
|
+
/** Log responses to requests. */
|
|
15
|
+
onResponse = logRequestResponse,
|
|
16
|
+
/** Log errors for requests. */
|
|
17
|
+
onError = logRequestError) {
|
|
18
|
+
super(source);
|
|
19
|
+
this._logRequest = onRequest;
|
|
20
|
+
this._logResponse = onResponse;
|
|
21
|
+
this._logError = onError;
|
|
22
|
+
}
|
|
23
|
+
async fetch(request) {
|
|
24
|
+
try {
|
|
25
|
+
this._logRequest(request);
|
|
26
|
+
const response = await super.fetch(request);
|
|
27
|
+
this._logResponse(response, request);
|
|
28
|
+
return response;
|
|
29
|
+
}
|
|
30
|
+
catch (reason) {
|
|
31
|
+
this._logError(reason, request);
|
|
32
|
+
throw reason;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,143 +1,144 @@
|
|
|
1
|
+
import { ANSI_ICON_ERROR, ANSI_ICON_REQUEST, ANSI_ICON_RESPONSE, ANSI_ICON_SUCCESS } from "../../util/ansi.js";
|
|
1
2
|
import { ThroughDBProvider } from "./ThroughDBProvider.js";
|
|
2
3
|
/** Provider that logs operations to the console. */
|
|
3
4
|
export class DebugDBProvider extends ThroughDBProvider {
|
|
4
5
|
async getItem(collection, id) {
|
|
5
6
|
try {
|
|
6
|
-
console.debug(
|
|
7
|
+
console.debug(`${ANSI_ICON_REQUEST} GET ITEM`, collection.name, id);
|
|
7
8
|
const item = await super.getItem(collection, id);
|
|
8
|
-
console.debug(
|
|
9
|
+
console.debug(`${ANSI_ICON_RESPONSE} GET ITEM`, collection.name, id, item);
|
|
9
10
|
return item;
|
|
10
11
|
}
|
|
11
12
|
catch (reason) {
|
|
12
|
-
console.error(
|
|
13
|
+
console.error(`${ANSI_ICON_ERROR} GET ITEM`, collection.name, id, reason);
|
|
13
14
|
throw reason;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
async *getItemSequence(collection, id) {
|
|
17
18
|
try {
|
|
18
|
-
console.debug(
|
|
19
|
+
console.debug(`${ANSI_ICON_REQUEST} SEQUENCE ITEM`, collection.name, id);
|
|
19
20
|
for await (const item of super.getItemSequence(collection, id)) {
|
|
20
|
-
console.debug(
|
|
21
|
+
console.debug(`${ANSI_ICON_RESPONSE} SEQUENCE ITEM`, collection.name, id, item);
|
|
21
22
|
yield item;
|
|
22
23
|
}
|
|
23
|
-
console.debug(
|
|
24
|
+
console.debug(`${ANSI_ICON_SUCCESS} SEQUENCE ITEM`, collection.name, id);
|
|
24
25
|
}
|
|
25
26
|
catch (thrown) {
|
|
26
|
-
console.error(
|
|
27
|
+
console.error(`${ANSI_ICON_ERROR} SEQUENCE ITEM`, collection.name, id, thrown);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
async addItem(collection, data) {
|
|
30
31
|
try {
|
|
31
|
-
console.debug(
|
|
32
|
+
console.debug(`${ANSI_ICON_REQUEST} ADD ITEM`, collection.name, data);
|
|
32
33
|
const id = await super.addItem(collection, data);
|
|
33
|
-
console.debug(
|
|
34
|
+
console.debug(`${ANSI_ICON_SUCCESS} ADD ITEM`, collection.name, id, data);
|
|
34
35
|
return id;
|
|
35
36
|
}
|
|
36
37
|
catch (reason) {
|
|
37
|
-
console.error(
|
|
38
|
+
console.error(`${ANSI_ICON_ERROR} ADD ITEM`, collection.name, data, reason);
|
|
38
39
|
throw reason;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
async setItem(collection, id, data) {
|
|
42
43
|
try {
|
|
43
|
-
console.debug(
|
|
44
|
+
console.debug(`${ANSI_ICON_REQUEST} SET ITEM`, collection.name, id, data);
|
|
44
45
|
await super.setItem(collection, id, data);
|
|
45
|
-
console.debug(
|
|
46
|
+
console.debug(`${ANSI_ICON_SUCCESS} SET ITEM`, collection.name, id, data);
|
|
46
47
|
}
|
|
47
48
|
catch (reason) {
|
|
48
|
-
console.error(
|
|
49
|
+
console.error(`${ANSI_ICON_ERROR} SET ITEM`, collection.name, id, data, reason);
|
|
49
50
|
throw reason;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
async updateItem(collection, id, updates) {
|
|
53
54
|
try {
|
|
54
|
-
console.debug(
|
|
55
|
+
console.debug(`${ANSI_ICON_REQUEST} UPDATE ITEM`, collection.name, id, updates);
|
|
55
56
|
await super.updateItem(collection, id, updates);
|
|
56
|
-
console.debug(
|
|
57
|
+
console.debug(`${ANSI_ICON_SUCCESS} UPDATE ITEM`, collection.name, id, updates);
|
|
57
58
|
}
|
|
58
59
|
catch (reason) {
|
|
59
|
-
console.error(
|
|
60
|
+
console.error(`${ANSI_ICON_ERROR} UPDATE ITEM`, collection.name, id, updates, reason);
|
|
60
61
|
throw reason;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
async deleteItem(collection, id) {
|
|
64
65
|
try {
|
|
65
|
-
console.debug(
|
|
66
|
+
console.debug(`${ANSI_ICON_REQUEST} DELETE`, collection.name, id);
|
|
66
67
|
await super.deleteItem(collection, id);
|
|
67
|
-
console.debug(
|
|
68
|
+
console.debug(`${ANSI_ICON_SUCCESS} DELETE`, collection.name, id);
|
|
68
69
|
}
|
|
69
70
|
catch (reason) {
|
|
70
|
-
console.error(
|
|
71
|
+
console.error(`${ANSI_ICON_ERROR} DELETE`, collection.name, id, reason);
|
|
71
72
|
throw reason;
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
async countQuery(collection, query) {
|
|
75
76
|
try {
|
|
76
|
-
console.debug(
|
|
77
|
+
console.debug(`${ANSI_ICON_REQUEST} COUNT QUERY`, collection.name, query);
|
|
77
78
|
const count = await super.countQuery(collection, query);
|
|
78
|
-
console.debug(
|
|
79
|
+
console.debug(`${ANSI_ICON_RESPONSE} COUNT QUERY`, collection.name, query, count);
|
|
79
80
|
return count;
|
|
80
81
|
}
|
|
81
82
|
catch (reason) {
|
|
82
|
-
console.error(
|
|
83
|
+
console.error(`${ANSI_ICON_ERROR} COUNT QUERY`, collection.name, query, reason);
|
|
83
84
|
throw reason;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
async getQuery(collection, query) {
|
|
87
88
|
try {
|
|
88
|
-
console.debug(
|
|
89
|
+
console.debug(`${ANSI_ICON_REQUEST} GET`, collection.name, query);
|
|
89
90
|
const items = await super.getQuery(collection, query);
|
|
90
|
-
console.debug(
|
|
91
|
+
console.debug(`${ANSI_ICON_RESPONSE} GET`, collection.name, query, items);
|
|
91
92
|
return items;
|
|
92
93
|
}
|
|
93
94
|
catch (reason) {
|
|
94
|
-
console.error(
|
|
95
|
+
console.error(`${ANSI_ICON_ERROR} GET`, collection.name, query, reason);
|
|
95
96
|
throw reason;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
async *getQuerySequence(collection, query) {
|
|
99
100
|
try {
|
|
100
|
-
console.debug(
|
|
101
|
+
console.debug(`${ANSI_ICON_REQUEST} SEQUENCE QUERY`, collection.name, query);
|
|
101
102
|
for await (const items of super.getQuerySequence(collection, query)) {
|
|
102
|
-
console.debug(
|
|
103
|
+
console.debug(`${ANSI_ICON_RESPONSE} SEQUENCE QUERY`, collection.name, query, items);
|
|
103
104
|
yield items;
|
|
104
105
|
}
|
|
105
|
-
console.debug(
|
|
106
|
+
console.debug(`${ANSI_ICON_SUCCESS} SEQUENCE QUERY`, collection.name, query);
|
|
106
107
|
}
|
|
107
108
|
catch (thrown) {
|
|
108
|
-
console.error(
|
|
109
|
+
console.error(`${ANSI_ICON_ERROR} SEQUENCE QUERY`, collection.name, query, thrown);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
async setQuery(collection, query, data) {
|
|
112
113
|
try {
|
|
113
|
-
console.debug(
|
|
114
|
+
console.debug(`${ANSI_ICON_REQUEST} SET QUERY`, collection.name, query, data);
|
|
114
115
|
await super.setQuery(collection, query, data);
|
|
115
|
-
console.debug(
|
|
116
|
+
console.debug(`${ANSI_ICON_SUCCESS} SET QUERY`, collection.name, query, data);
|
|
116
117
|
}
|
|
117
118
|
catch (reason) {
|
|
118
|
-
console.error(
|
|
119
|
+
console.error(`${ANSI_ICON_ERROR} SET QUERY`, collection.name, query, data, reason);
|
|
119
120
|
throw reason;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
async updateQuery(collection, query, updates) {
|
|
123
124
|
try {
|
|
124
|
-
console.debug(
|
|
125
|
+
console.debug(`${ANSI_ICON_REQUEST} UPDATE QUERY`, collection.name, query, updates);
|
|
125
126
|
await super.updateQuery(collection, query, updates);
|
|
126
|
-
console.debug(
|
|
127
|
+
console.debug(`${ANSI_ICON_SUCCESS} UPDATE QUERY`, collection.name, query, updates);
|
|
127
128
|
}
|
|
128
129
|
catch (reason) {
|
|
129
|
-
console.error(
|
|
130
|
+
console.error(`${ANSI_ICON_ERROR} UPDATE QUERY`, collection.name, query, updates, reason);
|
|
130
131
|
throw reason;
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
async deleteQuery(collection, query) {
|
|
134
135
|
try {
|
|
135
|
-
console.debug(
|
|
136
|
+
console.debug(`${ANSI_ICON_REQUEST} DELETE QUERY`, collection.name, query);
|
|
136
137
|
await super.deleteQuery(collection, query);
|
|
137
|
-
console.debug(
|
|
138
|
+
console.debug(`${ANSI_ICON_SUCCESS} DELETE QUERY`, collection.name, query);
|
|
138
139
|
}
|
|
139
140
|
catch (reason) {
|
|
140
|
-
console.error(
|
|
141
|
+
console.error(`${ANSI_ICON_ERROR} DELETE QUERY`, collection.name, query, reason);
|
|
141
142
|
throw reason;
|
|
142
143
|
}
|
|
143
144
|
}
|
package/package.json
CHANGED
package/util/ansi.d.ts
CHANGED
|
@@ -13,3 +13,8 @@ export declare const ANSI_UNDERLINE = "\u001B[4m";
|
|
|
13
13
|
export declare const ANSI_STRIKE = "\u001B[9m";
|
|
14
14
|
export declare const ANSI_INVERSE = "\u001B[7m";
|
|
15
15
|
export declare const ANSI_RESET = "\u001B[0m";
|
|
16
|
+
export declare const ANSI_ICON_WAITING = "\u001B[34m\u22EF\u001B[0m";
|
|
17
|
+
export declare const ANSI_ICON_SUCCESS = "\u001B[32m\u2713\u001B[0m";
|
|
18
|
+
export declare const ANSI_ICON_ERROR = "\u001B[31m\u2717\u001B[0m";
|
|
19
|
+
export declare const ANSI_ICON_REQUEST = "\u001B[34m\u2192\u001B[0m";
|
|
20
|
+
export declare const ANSI_ICON_RESPONSE = "\u001B[34m\u2190\u001B[0m";
|
package/util/ansi.js
CHANGED
|
@@ -16,3 +16,9 @@ export const ANSI_STRIKE = "\x1b[9m";
|
|
|
16
16
|
export const ANSI_INVERSE = "\x1b[7m";
|
|
17
17
|
// Reset.
|
|
18
18
|
export const ANSI_RESET = "\x1b[0m";
|
|
19
|
+
// Icons.
|
|
20
|
+
export const ANSI_ICON_WAITING = "\x1b[34m⋯\x1b[0m"; // ⋯
|
|
21
|
+
export const ANSI_ICON_SUCCESS = "\x1b[32m✓\x1b[0m"; // ✓
|
|
22
|
+
export const ANSI_ICON_ERROR = "\x1b[31m✗\x1b[0m"; // ✗
|
|
23
|
+
export const ANSI_ICON_REQUEST = "\x1b[34m→\x1b[0m"; // →
|
|
24
|
+
export const ANSI_ICON_RESPONSE = "\x1b[34m←\x1b[0m"; // ←
|
package/util/log.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noConsole: This file's purpose is to write logs. */
|
|
2
|
+
/** Log a `Request` */
|
|
3
|
+
export declare function logRequest(request: Request): Promise<void>;
|
|
4
|
+
/** Log a `Response` to a `Request` */
|
|
5
|
+
export declare function logRequestResponse(response: Response, request: Request): Promise<void>;
|
|
6
|
+
/** Log an `Error` from a `Request` */
|
|
7
|
+
export declare function logRequestError(reason: unknown, request: Request): void;
|
package/util/log.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noConsole: This file's purpose is to write logs. */
|
|
2
|
+
import { ANSI_ICON_ERROR, ANSI_ICON_REQUEST, ANSI_ICON_RESPONSE } from "./ansi.js";
|
|
3
|
+
import { debug, debugFullRequest, debugFullResponse, debugRequest } from "./debug.js";
|
|
4
|
+
/** Log a `Request` */
|
|
5
|
+
export async function logRequest(request) {
|
|
6
|
+
console.log(`${ANSI_ICON_REQUEST} ${await debugFullRequest(request)}`);
|
|
7
|
+
}
|
|
8
|
+
/** Log a `Response` to a `Request` */
|
|
9
|
+
export async function logRequestResponse(response, request) {
|
|
10
|
+
console.log(`${ANSI_ICON_RESPONSE} ${debugRequest(request)}\n\n${await debugFullResponse(response)}`);
|
|
11
|
+
}
|
|
12
|
+
/** Log an `Error` from a `Request` */
|
|
13
|
+
export function logRequestError(reason, request) {
|
|
14
|
+
console.error(`${ANSI_ICON_ERROR} ${debugRequest(request)}\n\n${debug(reason)}`);
|
|
15
|
+
}
|