shelving 1.199.1 → 1.199.3
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/provider/DebugAPIProvider.js +8 -8
- package/db/provider/DebugDBProvider.js +39 -39
- package/package.json +1 -1
- package/util/ansi.d.ts +24 -19
- package/util/ansi.js +16 -6
- package/util/constants.d.ts +7 -0
- package/util/constants.js +8 -0
- package/util/env.d.ts +23 -0
- package/util/env.js +44 -0
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/log.js +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ANSI_FAILURE, ANSI_LEFT, ANSI_RIGHT, ANSI_SUCCESS, ANSI_WAITING } from "../../util/ansi.js";
|
|
2
2
|
import { debugFullRequest, debugFullResponse, debugRequest } from "../../util/debug.js";
|
|
3
3
|
import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
|
|
4
4
|
/** Provider that logs everything to the console in some detail to help diagnose issues in development. */
|
|
@@ -6,34 +6,34 @@ export class DebugAPIProvider extends ThroughAPIProvider {
|
|
|
6
6
|
getRequest(endpoint, payload, options, caller = this.getRequest) {
|
|
7
7
|
try {
|
|
8
8
|
const request = super.getRequest(endpoint, payload, options, caller);
|
|
9
|
-
console.debug(`${
|
|
9
|
+
console.debug(`${ANSI_WAITING} ${endpoint.toString()}`, payload);
|
|
10
10
|
return request;
|
|
11
11
|
}
|
|
12
12
|
catch (reason) {
|
|
13
|
-
console.error(`${
|
|
13
|
+
console.error(`${ANSI_FAILURE} ${endpoint.toString()}`, payload, reason);
|
|
14
14
|
throw reason;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
async fetch(request) {
|
|
18
18
|
try {
|
|
19
|
-
console.debug(`${
|
|
19
|
+
console.debug(`${ANSI_RIGHT} ${await debugFullRequest(request)}`);
|
|
20
20
|
const response = await super.fetch(request);
|
|
21
|
-
console.debug(`${
|
|
21
|
+
console.debug(`${ANSI_LEFT} ${debugRequest(request)}\n\n${await debugFullResponse(response)}`);
|
|
22
22
|
return response;
|
|
23
23
|
}
|
|
24
24
|
catch (reason) {
|
|
25
|
-
console.error(`${
|
|
25
|
+
console.error(`${ANSI_FAILURE} ${debugRequest(request)}`, reason);
|
|
26
26
|
throw reason;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
async parseResponse(endpoint, response, caller = this.parseResponse) {
|
|
30
30
|
try {
|
|
31
31
|
const result = await super.parseResponse(endpoint, response, caller);
|
|
32
|
-
console.debug(`${
|
|
32
|
+
console.debug(`${ANSI_SUCCESS} ${endpoint.toString()}`, result);
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
35
35
|
catch (reason) {
|
|
36
|
-
console.error(`${
|
|
36
|
+
console.error(`${ANSI_FAILURE} ${endpoint.toString()}`, reason);
|
|
37
37
|
throw reason;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ANSI_FAILURE, ANSI_LEFT, ANSI_RIGHT, ANSI_SUCCESS } from "../../util/ansi.js";
|
|
2
2
|
import { ThroughDBProvider } from "./ThroughDBProvider.js";
|
|
3
3
|
/** Provider that logs operations to the console. */
|
|
4
4
|
export class DebugDBProvider extends ThroughDBProvider {
|
|
5
5
|
async getItem(collection, id) {
|
|
6
6
|
try {
|
|
7
|
-
console.debug(`${
|
|
7
|
+
console.debug(`${ANSI_RIGHT} GET ITEM`, collection.name, id);
|
|
8
8
|
const item = await super.getItem(collection, id);
|
|
9
|
-
console.debug(`${
|
|
9
|
+
console.debug(`${ANSI_LEFT} GET ITEM`, collection.name, id, item);
|
|
10
10
|
return item;
|
|
11
11
|
}
|
|
12
12
|
catch (reason) {
|
|
13
|
-
console.error(`${
|
|
13
|
+
console.error(`${ANSI_FAILURE} GET ITEM`, collection.name, id, reason);
|
|
14
14
|
throw reason;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
async *getItemSequence(collection, id) {
|
|
18
18
|
try {
|
|
19
|
-
console.debug(`${
|
|
19
|
+
console.debug(`${ANSI_RIGHT} SEQUENCE ITEM`, collection.name, id);
|
|
20
20
|
for await (const item of super.getItemSequence(collection, id)) {
|
|
21
|
-
console.debug(`${
|
|
21
|
+
console.debug(`${ANSI_LEFT} SEQUENCE ITEM`, collection.name, id, item);
|
|
22
22
|
yield item;
|
|
23
23
|
}
|
|
24
|
-
console.debug(`${
|
|
24
|
+
console.debug(`${ANSI_SUCCESS} SEQUENCE ITEM`, collection.name, id);
|
|
25
25
|
}
|
|
26
26
|
catch (thrown) {
|
|
27
|
-
console.error(`${
|
|
27
|
+
console.error(`${ANSI_FAILURE} SEQUENCE ITEM`, collection.name, id, thrown);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
async addItem(collection, data) {
|
|
31
31
|
try {
|
|
32
|
-
console.debug(`${
|
|
32
|
+
console.debug(`${ANSI_RIGHT} ADD ITEM`, collection.name, data);
|
|
33
33
|
const id = await super.addItem(collection, data);
|
|
34
|
-
console.debug(`${
|
|
34
|
+
console.debug(`${ANSI_SUCCESS} ADD ITEM`, collection.name, id, data);
|
|
35
35
|
return id;
|
|
36
36
|
}
|
|
37
37
|
catch (reason) {
|
|
38
|
-
console.error(`${
|
|
38
|
+
console.error(`${ANSI_FAILURE} ADD ITEM`, collection.name, data, reason);
|
|
39
39
|
throw reason;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
async setItem(collection, id, data) {
|
|
43
43
|
try {
|
|
44
|
-
console.debug(`${
|
|
44
|
+
console.debug(`${ANSI_RIGHT} SET ITEM`, collection.name, id, data);
|
|
45
45
|
await super.setItem(collection, id, data);
|
|
46
|
-
console.debug(`${
|
|
46
|
+
console.debug(`${ANSI_SUCCESS} SET ITEM`, collection.name, id, data);
|
|
47
47
|
}
|
|
48
48
|
catch (reason) {
|
|
49
|
-
console.error(`${
|
|
49
|
+
console.error(`${ANSI_FAILURE} SET ITEM`, collection.name, id, data, reason);
|
|
50
50
|
throw reason;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
async updateItem(collection, id, updates) {
|
|
54
54
|
try {
|
|
55
|
-
console.debug(`${
|
|
55
|
+
console.debug(`${ANSI_RIGHT} UPDATE ITEM`, collection.name, id, updates);
|
|
56
56
|
await super.updateItem(collection, id, updates);
|
|
57
|
-
console.debug(`${
|
|
57
|
+
console.debug(`${ANSI_SUCCESS} UPDATE ITEM`, collection.name, id, updates);
|
|
58
58
|
}
|
|
59
59
|
catch (reason) {
|
|
60
|
-
console.error(`${
|
|
60
|
+
console.error(`${ANSI_FAILURE} UPDATE ITEM`, collection.name, id, updates, reason);
|
|
61
61
|
throw reason;
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
async deleteItem(collection, id) {
|
|
65
65
|
try {
|
|
66
|
-
console.debug(`${
|
|
66
|
+
console.debug(`${ANSI_RIGHT} DELETE`, collection.name, id);
|
|
67
67
|
await super.deleteItem(collection, id);
|
|
68
|
-
console.debug(`${
|
|
68
|
+
console.debug(`${ANSI_SUCCESS} DELETE`, collection.name, id);
|
|
69
69
|
}
|
|
70
70
|
catch (reason) {
|
|
71
|
-
console.error(`${
|
|
71
|
+
console.error(`${ANSI_FAILURE} DELETE`, collection.name, id, reason);
|
|
72
72
|
throw reason;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async countQuery(collection, query) {
|
|
76
76
|
try {
|
|
77
|
-
console.debug(`${
|
|
77
|
+
console.debug(`${ANSI_RIGHT} COUNT QUERY`, collection.name, query);
|
|
78
78
|
const count = await super.countQuery(collection, query);
|
|
79
|
-
console.debug(`${
|
|
79
|
+
console.debug(`${ANSI_LEFT} COUNT QUERY`, collection.name, query, count);
|
|
80
80
|
return count;
|
|
81
81
|
}
|
|
82
82
|
catch (reason) {
|
|
83
|
-
console.error(`${
|
|
83
|
+
console.error(`${ANSI_FAILURE} COUNT QUERY`, collection.name, query, reason);
|
|
84
84
|
throw reason;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
async getQuery(collection, query) {
|
|
88
88
|
try {
|
|
89
|
-
console.debug(`${
|
|
89
|
+
console.debug(`${ANSI_RIGHT} GET`, collection.name, query);
|
|
90
90
|
const items = await super.getQuery(collection, query);
|
|
91
|
-
console.debug(`${
|
|
91
|
+
console.debug(`${ANSI_LEFT} GET`, collection.name, query, items);
|
|
92
92
|
return items;
|
|
93
93
|
}
|
|
94
94
|
catch (reason) {
|
|
95
|
-
console.error(`${
|
|
95
|
+
console.error(`${ANSI_FAILURE} GET`, collection.name, query, reason);
|
|
96
96
|
throw reason;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
async *getQuerySequence(collection, query) {
|
|
100
100
|
try {
|
|
101
|
-
console.debug(`${
|
|
101
|
+
console.debug(`${ANSI_RIGHT} SEQUENCE QUERY`, collection.name, query);
|
|
102
102
|
for await (const items of super.getQuerySequence(collection, query)) {
|
|
103
|
-
console.debug(`${
|
|
103
|
+
console.debug(`${ANSI_LEFT} SEQUENCE QUERY`, collection.name, query, items);
|
|
104
104
|
yield items;
|
|
105
105
|
}
|
|
106
|
-
console.debug(`${
|
|
106
|
+
console.debug(`${ANSI_SUCCESS} SEQUENCE QUERY`, collection.name, query);
|
|
107
107
|
}
|
|
108
108
|
catch (thrown) {
|
|
109
|
-
console.error(`${
|
|
109
|
+
console.error(`${ANSI_FAILURE} SEQUENCE QUERY`, collection.name, query, thrown);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
async setQuery(collection, query, data) {
|
|
113
113
|
try {
|
|
114
|
-
console.debug(`${
|
|
114
|
+
console.debug(`${ANSI_RIGHT} SET QUERY`, collection.name, query, data);
|
|
115
115
|
await super.setQuery(collection, query, data);
|
|
116
|
-
console.debug(`${
|
|
116
|
+
console.debug(`${ANSI_SUCCESS} SET QUERY`, collection.name, query, data);
|
|
117
117
|
}
|
|
118
118
|
catch (reason) {
|
|
119
|
-
console.error(`${
|
|
119
|
+
console.error(`${ANSI_FAILURE} SET QUERY`, collection.name, query, data, reason);
|
|
120
120
|
throw reason;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
async updateQuery(collection, query, updates) {
|
|
124
124
|
try {
|
|
125
|
-
console.debug(`${
|
|
125
|
+
console.debug(`${ANSI_RIGHT} UPDATE QUERY`, collection.name, query, updates);
|
|
126
126
|
await super.updateQuery(collection, query, updates);
|
|
127
|
-
console.debug(`${
|
|
127
|
+
console.debug(`${ANSI_SUCCESS} UPDATE QUERY`, collection.name, query, updates);
|
|
128
128
|
}
|
|
129
129
|
catch (reason) {
|
|
130
|
-
console.error(`${
|
|
130
|
+
console.error(`${ANSI_FAILURE} UPDATE QUERY`, collection.name, query, updates, reason);
|
|
131
131
|
throw reason;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
async deleteQuery(collection, query) {
|
|
135
135
|
try {
|
|
136
|
-
console.debug(`${
|
|
136
|
+
console.debug(`${ANSI_RIGHT} DELETE QUERY`, collection.name, query);
|
|
137
137
|
await super.deleteQuery(collection, query);
|
|
138
|
-
console.debug(`${
|
|
138
|
+
console.debug(`${ANSI_SUCCESS} DELETE QUERY`, collection.name, query);
|
|
139
139
|
}
|
|
140
140
|
catch (reason) {
|
|
141
|
-
console.error(`${
|
|
141
|
+
console.error(`${ANSI_FAILURE} DELETE QUERY`, collection.name, query, reason);
|
|
142
142
|
throw reason;
|
|
143
143
|
}
|
|
144
144
|
}
|
package/package.json
CHANGED
package/util/ansi.d.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
1
|
+
import type { ImmutableArray } from "./array.js";
|
|
2
|
+
export declare const ANSI_DEFAULT: "\u001B[39m";
|
|
3
|
+
export declare const ANSI_BLACK: "\u001B[30m";
|
|
4
|
+
export declare const ANSI_RED: "\u001B[31m";
|
|
5
|
+
export declare const ANSI_GREEN: "\u001B[32m";
|
|
6
|
+
export declare const ANSI_YELLOW: "\u001B[33m";
|
|
7
|
+
export declare const ANSI_BLUE: "\u001B[34m";
|
|
8
|
+
export declare const ANSI_MAGENTA: "\u001B[35m";
|
|
9
|
+
export declare const ANSI_CYAN: "\u001B[36m";
|
|
10
|
+
export declare const ANSI_WHITE: "\u001B[37m";
|
|
11
|
+
export declare const ANSI_BOLD: "\u001B[1m";
|
|
12
|
+
export declare const ANSI_ITALIC: "\u001B[3m";
|
|
13
|
+
export declare const ANSI_UNDERLINE: "\u001B[4m";
|
|
14
|
+
export declare const ANSI_STRIKE: "\u001B[9m";
|
|
15
|
+
export declare const ANSI_INVERSE: "\u001B[7m";
|
|
15
16
|
export declare const ANSI_RESET = "\u001B[0m";
|
|
16
|
-
|
|
17
|
-
export declare
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
17
|
+
/** Wrap a string in `ANSI_RED` or the ANSI color/style codes (at the start), and `ANSI_RESET` at the end. */
|
|
18
|
+
export declare function ansiWrap(input: string, ...wrappers: ImmutableArray<string>): string;
|
|
19
|
+
export declare const ANSI_WAITING: string;
|
|
20
|
+
export declare const ANSI_SUCCESS: string;
|
|
21
|
+
export declare const ANSI_FAILURE: string;
|
|
22
|
+
export declare const ANSI_UP: string;
|
|
23
|
+
export declare const ANSI_DOWN: string;
|
|
24
|
+
export declare const ANSI_RIGHT: string;
|
|
25
|
+
export declare const ANSI_LEFT: string;
|
package/util/ansi.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { DOWN, FAILURE, LEFT, RIGHT, SUCCESS, UP, WAITING } from "./constants.js";
|
|
2
|
+
import { NO_COLOR } from "./env.js";
|
|
1
3
|
// Colors.
|
|
2
4
|
export const ANSI_DEFAULT = "\x1b[39m";
|
|
3
5
|
export const ANSI_BLACK = "\x1b[30m";
|
|
@@ -16,9 +18,17 @@ export const ANSI_STRIKE = "\x1b[9m";
|
|
|
16
18
|
export const ANSI_INVERSE = "\x1b[7m";
|
|
17
19
|
// Reset.
|
|
18
20
|
export const ANSI_RESET = "\x1b[0m";
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
/** Wrap a string in `ANSI_RED` or the ANSI color/style codes (at the start), and `ANSI_RESET` at the end. */
|
|
22
|
+
export function ansiWrap(input, ...wrappers) {
|
|
23
|
+
if (NO_COLOR)
|
|
24
|
+
return input;
|
|
25
|
+
return `${wrappers.join("")}${input}${ANSI_RESET}`;
|
|
26
|
+
}
|
|
27
|
+
// Coloured icons.
|
|
28
|
+
export const ANSI_WAITING = ansiWrap(WAITING, ANSI_BLUE);
|
|
29
|
+
export const ANSI_SUCCESS = ansiWrap(SUCCESS, ANSI_GREEN);
|
|
30
|
+
export const ANSI_FAILURE = ansiWrap(FAILURE, ANSI_RED);
|
|
31
|
+
export const ANSI_UP = ansiWrap(UP, ANSI_BLUE);
|
|
32
|
+
export const ANSI_DOWN = ansiWrap(DOWN, ANSI_BLUE);
|
|
33
|
+
export const ANSI_RIGHT = ansiWrap(RIGHT, ANSI_BLUE);
|
|
34
|
+
export const ANSI_LEFT = ansiWrap(LEFT, ANSI_BLUE);
|
package/util/constants.d.ts
CHANGED
|
@@ -36,3 +36,10 @@ export declare const ABORT: unique symbol;
|
|
|
36
36
|
export declare const NONE: unique symbol;
|
|
37
37
|
/** The `SKIP` symbol indicates something should be silently skipped. */
|
|
38
38
|
export declare const SKIP: unique symbol;
|
|
39
|
+
export declare const WAITING = "\u22EF";
|
|
40
|
+
export declare const SUCCESS = "\u2713";
|
|
41
|
+
export declare const FAILURE = "\u2717";
|
|
42
|
+
export declare const UP = "\u2191";
|
|
43
|
+
export declare const DOWN = "\u2193";
|
|
44
|
+
export declare const RIGHT = "\u2192";
|
|
45
|
+
export declare const LEFT = "\u2190";
|
package/util/constants.js
CHANGED
|
@@ -36,3 +36,11 @@ export const ABORT = Symbol("shelving/ABORT");
|
|
|
36
36
|
export const NONE = Symbol("shelving/NONE");
|
|
37
37
|
/** The `SKIP` symbol indicates something should be silently skipped. */
|
|
38
38
|
export const SKIP = Symbol("shelving/SKIP");
|
|
39
|
+
// Icons.
|
|
40
|
+
export const WAITING = "⋯";
|
|
41
|
+
export const SUCCESS = "✓";
|
|
42
|
+
export const FAILURE = "✗";
|
|
43
|
+
export const UP = "↑";
|
|
44
|
+
export const DOWN = "↓";
|
|
45
|
+
export const RIGHT = "→";
|
|
46
|
+
export const LEFT = "←";
|
package/util/env.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AnyCaller } from "./function.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get a `process.env` variable safely in all environments, or `undefined` if it doesn't exist or this environment does not support `process.env` (i.e. web environments).
|
|
4
|
+
*/
|
|
5
|
+
export declare function getEnv(name: string): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Get a `process.env` variable safely in all environments, or throw `RequiredError` if it doesn't exist or this environment does not support `process.env` (i.e. web environments).
|
|
8
|
+
*/
|
|
9
|
+
export declare function requireEnv(name: string, caller?: AnyCaller): string;
|
|
10
|
+
/**
|
|
11
|
+
* Get a `process.env` variable and resolve it to to `true` or `false`, or `undefined` if it isn't a true/false value.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getEnvBoolean(name: string): boolean | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Get a `process.env` variable and resolve it to to `true` or `false`
|
|
16
|
+
*
|
|
17
|
+
* @returns `false` if the environment variable is `0`, `off`, `no`, `false`
|
|
18
|
+
* @returns `true` if the environment variable is `1`, `on`, `yes`, `true`
|
|
19
|
+
* @throws `RequiredError` if the env variable is any other value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function requireEnvBoolean(name: string, caller?: AnyCaller): boolean;
|
|
22
|
+
/** The `NO_COLOR` environment variable is commonly used to indicate that ANSI output shouldn't have color. */
|
|
23
|
+
export declare const NO_COLOR: boolean;
|
package/util/env.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RequiredError } from "../error/RequiredError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get a `process.env` variable safely in all environments, or `undefined` if it doesn't exist or this environment does not support `process.env` (i.e. web environments).
|
|
4
|
+
*/
|
|
5
|
+
export function getEnv(name) {
|
|
6
|
+
if (typeof process === "object" && typeof process.env === "object")
|
|
7
|
+
return process.env[name];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get a `process.env` variable safely in all environments, or throw `RequiredError` if it doesn't exist or this environment does not support `process.env` (i.e. web environments).
|
|
11
|
+
*/
|
|
12
|
+
export function requireEnv(name, caller = requireEnv) {
|
|
13
|
+
const env = getEnv(name);
|
|
14
|
+
if (typeof env !== "string")
|
|
15
|
+
throw new RequiredError(`Environment variable "${name}" is required`, { caller });
|
|
16
|
+
return env;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get a `process.env` variable and resolve it to to `true` or `false`, or `undefined` if it isn't a true/false value.
|
|
20
|
+
*/
|
|
21
|
+
export function getEnvBoolean(name) {
|
|
22
|
+
const env = getEnv(name)?.toLowerCase();
|
|
23
|
+
if (env && _TRUES.includes(env))
|
|
24
|
+
return true;
|
|
25
|
+
if (env && _FALSES.includes(env))
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const _TRUES = [`1`, `on`, `yes`, `true`];
|
|
29
|
+
const _FALSES = [`0`, `off`, `no`, `false`];
|
|
30
|
+
/**
|
|
31
|
+
* Get a `process.env` variable and resolve it to to `true` or `false`
|
|
32
|
+
*
|
|
33
|
+
* @returns `false` if the environment variable is `0`, `off`, `no`, `false`
|
|
34
|
+
* @returns `true` if the environment variable is `1`, `on`, `yes`, `true`
|
|
35
|
+
* @throws `RequiredError` if the env variable is any other value.
|
|
36
|
+
*/
|
|
37
|
+
export function requireEnvBoolean(name, caller = requireEnvBoolean) {
|
|
38
|
+
const env = getEnv(name);
|
|
39
|
+
if (typeof env !== "boolean")
|
|
40
|
+
throw new RequiredError(`Environment variable "${name}" must be boolean`, { caller });
|
|
41
|
+
return env;
|
|
42
|
+
}
|
|
43
|
+
/** The `NO_COLOR` environment variable is commonly used to indicate that ANSI output shouldn't have color. */
|
|
44
|
+
export const NO_COLOR = getEnvBoolean("NO_COLOR") ?? false;
|
package/util/index.d.ts
CHANGED
package/util/index.js
CHANGED
package/util/log.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/noConsole: This file's purpose is to write logs. */
|
|
2
|
-
import {
|
|
2
|
+
import { ANSI_FAILURE, ANSI_LEFT, ANSI_RIGHT } from "./ansi.js";
|
|
3
3
|
import { debug, debugFullRequest, debugFullResponse, debugRequest } from "./debug.js";
|
|
4
4
|
/** Log a `Request` */
|
|
5
5
|
export async function logRequest(request) {
|
|
6
|
-
console.log(`${
|
|
6
|
+
console.log(`${ANSI_RIGHT} ${await debugFullRequest(request)}`);
|
|
7
7
|
}
|
|
8
8
|
/** Log a `Response` to a `Request` */
|
|
9
9
|
export async function logRequestResponse(response, request) {
|
|
10
|
-
console.log(`${
|
|
10
|
+
console.log(`${ANSI_LEFT} ${debugRequest(request)}\n\n${await debugFullResponse(response)}`);
|
|
11
11
|
}
|
|
12
12
|
/** Log an `Error` from a `Request` */
|
|
13
13
|
export function logRequestError(reason, request) {
|
|
14
|
-
console.error(`${
|
|
14
|
+
console.error(`${ANSI_FAILURE} ${debugRequest(request)}\n\n${debug(reason)}`);
|
|
15
15
|
}
|