@trpc/client 11.0.0-rc.366 → 11.0.0-rc.369
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/dist/bundle-analysis.json +17 -17
- package/dist/links/loggerLink.d.ts +6 -1
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +24 -29
- package/dist/links/loggerLink.mjs +24 -29
- package/package.json +4 -4
- package/src/links/loggerLink.ts +42 -34
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 29,
|
|
2
|
+
"bundleSize": 46894,
|
|
3
|
+
"bundleOrigSize": 66367,
|
|
4
|
+
"bundleReduction": 29.34,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/links/wsLink.ts",
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
],
|
|
14
14
|
"removedExports": [],
|
|
15
15
|
"dependents": [],
|
|
16
|
-
"percent": 25.
|
|
16
|
+
"percent": 25.71,
|
|
17
17
|
"reduction": 11.68
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"id": "/src/links/loggerLink.ts",
|
|
21
|
-
"size":
|
|
22
|
-
"origSize":
|
|
21
|
+
"size": 5457,
|
|
22
|
+
"origSize": 6694,
|
|
23
23
|
"renderedExports": [
|
|
24
24
|
"loggerLink"
|
|
25
25
|
],
|
|
26
26
|
"removedExports": [],
|
|
27
27
|
"dependents": [],
|
|
28
|
-
"percent": 11.
|
|
29
|
-
"reduction":
|
|
28
|
+
"percent": 11.64,
|
|
29
|
+
"reduction": 18.48
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"id": "/src/internals/dataLoader.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependents": [
|
|
40
40
|
"/src/links/internals/createHTTPBatchLink.ts"
|
|
41
41
|
],
|
|
42
|
-
"percent": 9.
|
|
42
|
+
"percent": 9.4,
|
|
43
43
|
"reduction": 7.49
|
|
44
44
|
},
|
|
45
45
|
{
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"/src/links/internals/createHTTPBatchLink.ts",
|
|
63
63
|
"/src/links/internals/parseJSONStream.ts"
|
|
64
64
|
],
|
|
65
|
-
"percent": 9.
|
|
65
|
+
"percent": 9.4,
|
|
66
66
|
"reduction": 36.18
|
|
67
67
|
},
|
|
68
68
|
{
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"dependents": [
|
|
78
78
|
"/src/links/httpBatchStreamLink.ts"
|
|
79
79
|
],
|
|
80
|
-
"percent": 8.
|
|
80
|
+
"percent": 8.54,
|
|
81
81
|
"reduction": 20.45
|
|
82
82
|
},
|
|
83
83
|
{
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"/src/links/httpBatchLink.ts",
|
|
93
93
|
"/src/links/httpBatchStreamLink.ts"
|
|
94
94
|
],
|
|
95
|
-
"percent": 6.
|
|
95
|
+
"percent": 6.28,
|
|
96
96
|
"reduction": 20.67
|
|
97
97
|
},
|
|
98
98
|
{
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"/src/createTRPCUntypedClient.ts",
|
|
108
108
|
"/src/createTRPCClient.ts"
|
|
109
109
|
],
|
|
110
|
-
"percent": 4.
|
|
110
|
+
"percent": 4.9,
|
|
111
111
|
"reduction": 45.35
|
|
112
112
|
},
|
|
113
113
|
{
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
],
|
|
121
121
|
"removedExports": [],
|
|
122
122
|
"dependents": [],
|
|
123
|
-
"percent": 4.
|
|
123
|
+
"percent": 4.63,
|
|
124
124
|
"reduction": 21.23
|
|
125
125
|
},
|
|
126
126
|
{
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"/src/links/internals/createHTTPBatchLink.ts",
|
|
140
140
|
"/src/links/internals/httpUtils.ts"
|
|
141
141
|
],
|
|
142
|
-
"percent": 3.
|
|
142
|
+
"percent": 3.98,
|
|
143
143
|
"reduction": 45.71
|
|
144
144
|
},
|
|
145
145
|
{
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
],
|
|
152
152
|
"removedExports": [],
|
|
153
153
|
"dependents": [],
|
|
154
|
-
"percent": 2.
|
|
154
|
+
"percent": 2.86,
|
|
155
155
|
"reduction": 38.42
|
|
156
156
|
},
|
|
157
157
|
{
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
],
|
|
181
181
|
"removedExports": [],
|
|
182
182
|
"dependents": [],
|
|
183
|
-
"percent": 2.
|
|
183
|
+
"percent": 2.57,
|
|
184
184
|
"reduction": 21.09
|
|
185
185
|
},
|
|
186
186
|
{
|
|
@@ -27,6 +27,7 @@ type LoggerLinkFnOptions<TRouter extends AnyRouter> = Operation & ({
|
|
|
27
27
|
direction: 'up';
|
|
28
28
|
});
|
|
29
29
|
type LoggerLinkFn<TRouter extends AnyRouter> = (opts: LoggerLinkFnOptions<TRouter>) => void;
|
|
30
|
+
type ColorMode = 'ansi' | 'css' | 'none';
|
|
30
31
|
export interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
31
32
|
logger?: LoggerLinkFn<TRouter>;
|
|
32
33
|
enabled?: EnabledFn<TRouter>;
|
|
@@ -38,7 +39,11 @@ export interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
|
38
39
|
* Color mode
|
|
39
40
|
* @default typeof window === 'undefined' ? 'ansi' : 'css'
|
|
40
41
|
*/
|
|
41
|
-
colorMode?:
|
|
42
|
+
colorMode?: ColorMode;
|
|
43
|
+
/**
|
|
44
|
+
* Include context in the log - defaults to false unless `colorMode` is 'css'
|
|
45
|
+
*/
|
|
46
|
+
withContext?: boolean;
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
* @link https://trpc.io/docs/v11/client/links/loggerLink
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerLink.d.ts","sourceRoot":"","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EG;IACH,SAAS,EAAE,IAAI,CAAC;CACjB,CACJ,CAAC;AAEJ,KAAK,YAAY,CAAC,OAAO,SAAS,SAAS,IAAI,CAC7C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,KAC/B,IAAI,CAAC;AAEV,KAAK,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;AAEzC,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,SAAS;IAC1D,MAAM,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC7B;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAoID;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CAgDnB"}
|
package/dist/links/loggerLink.js
CHANGED
|
@@ -64,50 +64,42 @@ const palettes = {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
function constructPartsAndArgs(opts) {
|
|
67
|
-
const { direction , type , path , id , input } = opts;
|
|
67
|
+
const { direction , type , withContext , path , id , input } = opts;
|
|
68
68
|
const parts = [];
|
|
69
69
|
const args = [];
|
|
70
|
-
if (opts.colorMode === '
|
|
70
|
+
if (opts.colorMode === 'none') {
|
|
71
|
+
parts.push(direction === 'up' ? '>>' : '<<', type, `#${id}`, path);
|
|
72
|
+
} else if (opts.colorMode === 'ansi') {
|
|
71
73
|
const [lightRegular, darkRegular] = palettes.ansi.regular[type];
|
|
72
74
|
const [lightBold, darkBold] = palettes.ansi.bold[type];
|
|
73
75
|
const reset = '\x1b[0m';
|
|
74
76
|
parts.push(direction === 'up' ? lightRegular : darkRegular, direction === 'up' ? '>>' : '<<', type, direction === 'up' ? lightBold : darkBold, `#${id}`, path, reset);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
} else {
|
|
80
|
-
args.push({
|
|
81
|
-
input: opts.input,
|
|
82
|
-
// strip context from result cause it's too noisy in terminal wihtout collapse mode
|
|
83
|
-
result: 'result' in opts.result ? opts.result.result : opts.result,
|
|
84
|
-
elapsedMs: opts.elapsedMs
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
parts,
|
|
89
|
-
args
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const [light, dark] = palettes.css[type];
|
|
93
|
-
const css = `
|
|
77
|
+
} else {
|
|
78
|
+
// css color mode
|
|
79
|
+
const [light, dark] = palettes.css[type];
|
|
80
|
+
const css = `
|
|
94
81
|
background-color: #${direction === 'up' ? light : dark};
|
|
95
82
|
color: ${direction === 'up' ? 'black' : 'white'};
|
|
96
83
|
padding: 2px;
|
|
97
84
|
`;
|
|
98
|
-
|
|
99
|
-
|
|
85
|
+
parts.push('%c', direction === 'up' ? '>>' : '<<', type, `#${id}`, `%c${path}%c`, '%O');
|
|
86
|
+
args.push(css, `${css}; font-weight: bold;`, `${css}; font-weight: normal;`);
|
|
87
|
+
}
|
|
100
88
|
if (direction === 'up') {
|
|
101
|
-
args.push({
|
|
89
|
+
args.push(withContext ? {
|
|
102
90
|
input,
|
|
103
91
|
context: opts.context
|
|
92
|
+
} : {
|
|
93
|
+
input
|
|
104
94
|
});
|
|
105
95
|
} else {
|
|
106
96
|
args.push({
|
|
107
97
|
input,
|
|
108
98
|
result: opts.result,
|
|
109
99
|
elapsedMs: opts.elapsedMs,
|
|
110
|
-
|
|
100
|
+
...withContext && {
|
|
101
|
+
context: opts.context
|
|
102
|
+
}
|
|
111
103
|
});
|
|
112
104
|
}
|
|
113
105
|
return {
|
|
@@ -116,13 +108,14 @@ function constructPartsAndArgs(opts) {
|
|
|
116
108
|
};
|
|
117
109
|
}
|
|
118
110
|
// maybe this should be moved to it's own package
|
|
119
|
-
const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
|
|
111
|
+
const defaultLogger = ({ c =console , colorMode ='css' , withContext })=>(props)=>{
|
|
120
112
|
const rawInput = props.input;
|
|
121
113
|
const input = isFormData(rawInput) ? Object.fromEntries(rawInput) : rawInput;
|
|
122
114
|
const { parts , args } = constructPartsAndArgs({
|
|
123
115
|
...props,
|
|
124
116
|
colorMode,
|
|
125
|
-
input
|
|
117
|
+
input,
|
|
118
|
+
withContext
|
|
126
119
|
});
|
|
127
120
|
const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result) ? 'error' : 'log';
|
|
128
121
|
c[fn].apply(null, [
|
|
@@ -134,10 +127,12 @@ const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
|
|
|
134
127
|
*/ function loggerLink(opts = {}) {
|
|
135
128
|
const { enabled =()=>true } = opts;
|
|
136
129
|
const colorMode = opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
|
|
130
|
+
const withContext = opts.withContext ?? colorMode === 'css';
|
|
137
131
|
const { logger =defaultLogger({
|
|
138
132
|
c: opts.console,
|
|
139
|
-
colorMode
|
|
140
|
-
|
|
133
|
+
colorMode,
|
|
134
|
+
withContext
|
|
135
|
+
}) , } = opts;
|
|
141
136
|
return ()=>{
|
|
142
137
|
return ({ op , next })=>{
|
|
143
138
|
return observable.observable((observer)=>{
|
|
@@ -62,50 +62,42 @@ const palettes = {
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
function constructPartsAndArgs(opts) {
|
|
65
|
-
const { direction , type , path , id , input } = opts;
|
|
65
|
+
const { direction , type , withContext , path , id , input } = opts;
|
|
66
66
|
const parts = [];
|
|
67
67
|
const args = [];
|
|
68
|
-
if (opts.colorMode === '
|
|
68
|
+
if (opts.colorMode === 'none') {
|
|
69
|
+
parts.push(direction === 'up' ? '>>' : '<<', type, `#${id}`, path);
|
|
70
|
+
} else if (opts.colorMode === 'ansi') {
|
|
69
71
|
const [lightRegular, darkRegular] = palettes.ansi.regular[type];
|
|
70
72
|
const [lightBold, darkBold] = palettes.ansi.bold[type];
|
|
71
73
|
const reset = '\x1b[0m';
|
|
72
74
|
parts.push(direction === 'up' ? lightRegular : darkRegular, direction === 'up' ? '>>' : '<<', type, direction === 'up' ? lightBold : darkBold, `#${id}`, path, reset);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
args.push({
|
|
79
|
-
input: opts.input,
|
|
80
|
-
// strip context from result cause it's too noisy in terminal wihtout collapse mode
|
|
81
|
-
result: 'result' in opts.result ? opts.result.result : opts.result,
|
|
82
|
-
elapsedMs: opts.elapsedMs
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
parts,
|
|
87
|
-
args
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
const [light, dark] = palettes.css[type];
|
|
91
|
-
const css = `
|
|
75
|
+
} else {
|
|
76
|
+
// css color mode
|
|
77
|
+
const [light, dark] = palettes.css[type];
|
|
78
|
+
const css = `
|
|
92
79
|
background-color: #${direction === 'up' ? light : dark};
|
|
93
80
|
color: ${direction === 'up' ? 'black' : 'white'};
|
|
94
81
|
padding: 2px;
|
|
95
82
|
`;
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
parts.push('%c', direction === 'up' ? '>>' : '<<', type, `#${id}`, `%c${path}%c`, '%O');
|
|
84
|
+
args.push(css, `${css}; font-weight: bold;`, `${css}; font-weight: normal;`);
|
|
85
|
+
}
|
|
98
86
|
if (direction === 'up') {
|
|
99
|
-
args.push({
|
|
87
|
+
args.push(withContext ? {
|
|
100
88
|
input,
|
|
101
89
|
context: opts.context
|
|
90
|
+
} : {
|
|
91
|
+
input
|
|
102
92
|
});
|
|
103
93
|
} else {
|
|
104
94
|
args.push({
|
|
105
95
|
input,
|
|
106
96
|
result: opts.result,
|
|
107
97
|
elapsedMs: opts.elapsedMs,
|
|
108
|
-
|
|
98
|
+
...withContext && {
|
|
99
|
+
context: opts.context
|
|
100
|
+
}
|
|
109
101
|
});
|
|
110
102
|
}
|
|
111
103
|
return {
|
|
@@ -114,13 +106,14 @@ function constructPartsAndArgs(opts) {
|
|
|
114
106
|
};
|
|
115
107
|
}
|
|
116
108
|
// maybe this should be moved to it's own package
|
|
117
|
-
const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
|
|
109
|
+
const defaultLogger = ({ c =console , colorMode ='css' , withContext })=>(props)=>{
|
|
118
110
|
const rawInput = props.input;
|
|
119
111
|
const input = isFormData(rawInput) ? Object.fromEntries(rawInput) : rawInput;
|
|
120
112
|
const { parts , args } = constructPartsAndArgs({
|
|
121
113
|
...props,
|
|
122
114
|
colorMode,
|
|
123
|
-
input
|
|
115
|
+
input,
|
|
116
|
+
withContext
|
|
124
117
|
});
|
|
125
118
|
const fn = props.direction === 'down' && props.result && (props.result instanceof Error || 'error' in props.result.result) ? 'error' : 'log';
|
|
126
119
|
c[fn].apply(null, [
|
|
@@ -132,10 +125,12 @@ const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
|
|
|
132
125
|
*/ function loggerLink(opts = {}) {
|
|
133
126
|
const { enabled =()=>true } = opts;
|
|
134
127
|
const colorMode = opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
|
|
128
|
+
const withContext = opts.withContext ?? colorMode === 'css';
|
|
135
129
|
const { logger =defaultLogger({
|
|
136
130
|
c: opts.console,
|
|
137
|
-
colorMode
|
|
138
|
-
|
|
131
|
+
colorMode,
|
|
132
|
+
withContext
|
|
133
|
+
}) , } = opts;
|
|
139
134
|
return ()=>{
|
|
140
135
|
return ({ op , next })=>{
|
|
141
136
|
return observable((observer)=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.369+0fb9a1d0a",
|
|
4
4
|
"description": "The tRPC client library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,10 +76,10 @@
|
|
|
76
76
|
"!**/*.test.*"
|
|
77
77
|
],
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@trpc/server": "11.0.0-rc.
|
|
79
|
+
"@trpc/server": "11.0.0-rc.369+0fb9a1d0a"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@trpc/server": "11.0.0-rc.
|
|
82
|
+
"@trpc/server": "11.0.0-rc.369+0fb9a1d0a",
|
|
83
83
|
"@types/isomorphic-fetch": "^0.0.39",
|
|
84
84
|
"@types/node": "^20.10.0",
|
|
85
85
|
"eslint": "^8.56.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"funding": [
|
|
96
96
|
"https://trpc.io/sponsor"
|
|
97
97
|
],
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "0fb9a1d0a5ed26aa155b6d01d5deebe22cbf19cf"
|
|
99
99
|
}
|
package/src/links/loggerLink.ts
CHANGED
|
@@ -49,6 +49,8 @@ type LoggerLinkFn<TRouter extends AnyRouter> = (
|
|
|
49
49
|
opts: LoggerLinkFnOptions<TRouter>,
|
|
50
50
|
) => void;
|
|
51
51
|
|
|
52
|
+
type ColorMode = 'ansi' | 'css' | 'none';
|
|
53
|
+
|
|
52
54
|
export interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
53
55
|
logger?: LoggerLinkFn<TRouter>;
|
|
54
56
|
enabled?: EnabledFn<TRouter>;
|
|
@@ -60,7 +62,12 @@ export interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
|
60
62
|
* Color mode
|
|
61
63
|
* @default typeof window === 'undefined' ? 'ansi' : 'css'
|
|
62
64
|
*/
|
|
63
|
-
colorMode?:
|
|
65
|
+
colorMode?: ColorMode;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Include context in the log - defaults to false unless `colorMode` is 'css'
|
|
69
|
+
*/
|
|
70
|
+
withContext?: boolean;
|
|
64
71
|
}
|
|
65
72
|
|
|
66
73
|
function isFormData(value: unknown): value is FormData {
|
|
@@ -96,15 +103,18 @@ const palettes = {
|
|
|
96
103
|
|
|
97
104
|
function constructPartsAndArgs(
|
|
98
105
|
opts: LoggerLinkFnOptions<any> & {
|
|
99
|
-
colorMode:
|
|
106
|
+
colorMode: ColorMode;
|
|
107
|
+
withContext?: boolean;
|
|
100
108
|
},
|
|
101
109
|
) {
|
|
102
|
-
const { direction, type, path, id, input } = opts;
|
|
110
|
+
const { direction, type, withContext, path, id, input } = opts;
|
|
103
111
|
|
|
104
112
|
const parts: string[] = [];
|
|
105
113
|
const args: any[] = [];
|
|
106
114
|
|
|
107
|
-
if (opts.colorMode === '
|
|
115
|
+
if (opts.colorMode === 'none') {
|
|
116
|
+
parts.push(direction === 'up' ? '>>' : '<<', type, `#${id}`, path);
|
|
117
|
+
} else if (opts.colorMode === 'ansi') {
|
|
108
118
|
const [lightRegular, darkRegular] = palettes.ansi.regular[type];
|
|
109
119
|
const [lightBold, darkBold] = palettes.ansi.bold[type];
|
|
110
120
|
const reset = '\x1b[0m';
|
|
@@ -118,46 +128,38 @@ function constructPartsAndArgs(
|
|
|
118
128
|
path,
|
|
119
129
|
reset,
|
|
120
130
|
);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
args.push({
|
|
126
|
-
input: opts.input,
|
|
127
|
-
// strip context from result cause it's too noisy in terminal wihtout collapse mode
|
|
128
|
-
result: 'result' in opts.result ? opts.result.result : opts.result,
|
|
129
|
-
elapsedMs: opts.elapsedMs,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return { parts, args };
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const [light, dark] = palettes.css[type];
|
|
137
|
-
const css = `
|
|
131
|
+
} else {
|
|
132
|
+
// css color mode
|
|
133
|
+
const [light, dark] = palettes.css[type];
|
|
134
|
+
const css = `
|
|
138
135
|
background-color: #${direction === 'up' ? light : dark};
|
|
139
136
|
color: ${direction === 'up' ? 'black' : 'white'};
|
|
140
137
|
padding: 2px;
|
|
141
138
|
`;
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
parts.push(
|
|
141
|
+
'%c',
|
|
142
|
+
direction === 'up' ? '>>' : '<<',
|
|
143
|
+
type,
|
|
144
|
+
`#${id}`,
|
|
145
|
+
`%c${path}%c`,
|
|
146
|
+
'%O',
|
|
147
|
+
);
|
|
148
|
+
args.push(
|
|
149
|
+
css,
|
|
150
|
+
`${css}; font-weight: bold;`,
|
|
151
|
+
`${css}; font-weight: normal;`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
152
154
|
|
|
153
155
|
if (direction === 'up') {
|
|
154
|
-
args.push({ input, context: opts.context });
|
|
156
|
+
args.push(withContext ? { input, context: opts.context } : { input });
|
|
155
157
|
} else {
|
|
156
158
|
args.push({
|
|
157
159
|
input,
|
|
158
160
|
result: opts.result,
|
|
159
161
|
elapsedMs: opts.elapsedMs,
|
|
160
|
-
context: opts.context,
|
|
162
|
+
...(withContext && { context: opts.context }),
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
165
|
|
|
@@ -169,9 +171,11 @@ const defaultLogger =
|
|
|
169
171
|
<TRouter extends AnyRouter>({
|
|
170
172
|
c = console,
|
|
171
173
|
colorMode = 'css',
|
|
174
|
+
withContext,
|
|
172
175
|
}: {
|
|
173
176
|
c?: ConsoleEsque;
|
|
174
|
-
colorMode?:
|
|
177
|
+
colorMode?: ColorMode;
|
|
178
|
+
withContext?: boolean;
|
|
175
179
|
}): LoggerLinkFn<TRouter> =>
|
|
176
180
|
(props) => {
|
|
177
181
|
const rawInput = props.input;
|
|
@@ -183,6 +187,7 @@ const defaultLogger =
|
|
|
183
187
|
...props,
|
|
184
188
|
colorMode,
|
|
185
189
|
input,
|
|
190
|
+
withContext,
|
|
186
191
|
});
|
|
187
192
|
|
|
188
193
|
const fn: 'error' | 'log' =
|
|
@@ -205,7 +210,10 @@ export function loggerLink<TRouter extends AnyRouter = AnyRouter>(
|
|
|
205
210
|
|
|
206
211
|
const colorMode =
|
|
207
212
|
opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
|
|
208
|
-
const
|
|
213
|
+
const withContext = opts.withContext ?? colorMode === 'css';
|
|
214
|
+
const {
|
|
215
|
+
logger = defaultLogger({ c: opts.console, colorMode, withContext }),
|
|
216
|
+
} = opts;
|
|
209
217
|
|
|
210
218
|
return () => {
|
|
211
219
|
return ({ op, next }) => {
|