@trpc/client 10.0.0-alpha.16 → 10.0.0-alpha.19

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.
Files changed (58) hide show
  1. package/dist/TRPCClientError.d.ts +0 -8
  2. package/dist/TRPCClientError.d.ts.map +1 -1
  3. package/dist/index.js +582 -586
  4. package/dist/index.mjs +581 -585
  5. package/dist/internals/TRPCClient.d.ts +1 -9
  6. package/dist/internals/TRPCClient.d.ts.map +1 -1
  7. package/dist/links/dedupeLink.d.ts.map +1 -1
  8. package/dist/links/httpBatchLink.d.ts +1 -1
  9. package/dist/links/httpBatchLink.d.ts.map +1 -1
  10. package/dist/links/httpLink.d.ts +1 -1
  11. package/dist/links/httpLink.d.ts.map +1 -1
  12. package/dist/links/loggerLink.d.ts.map +1 -1
  13. package/dist/links/splitLink.d.ts +1 -1
  14. package/dist/links/splitLink.d.ts.map +1 -1
  15. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +1 -11
  16. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +214 -0
  17. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +6 -15
  18. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +214 -0
  19. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +210 -0
  20. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +1 -11
  21. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +67 -0
  22. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +6 -15
  23. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +67 -0
  24. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +63 -0
  25. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +1 -11
  26. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +89 -0
  27. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +6 -15
  28. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +89 -0
  29. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +85 -0
  30. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +1 -11
  31. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +19 -0
  32. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +6 -15
  33. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +19 -0
  34. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +15 -0
  35. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +1 -11
  36. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +395 -0
  37. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +6 -15
  38. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +395 -0
  39. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +390 -0
  40. package/observable/dist/trpc-client-rx.cjs.d.ts +1 -0
  41. package/observable/dist/trpc-client-rx.cjs.dev.js +9 -0
  42. package/observable/dist/trpc-client-rx.cjs.js +7 -0
  43. package/observable/dist/trpc-client-rx.cjs.prod.js +9 -0
  44. package/observable/dist/trpc-client-rx.esm.js +1 -0
  45. package/observable/index.d.ts +1 -0
  46. package/observable/index.js +1 -0
  47. package/package.json +9 -44
  48. package/src/TRPCClientError.ts +2 -10
  49. package/src/internals/TRPCClient.ts +7 -12
  50. package/src/links/dedupeLink.test.ts +1 -1
  51. package/src/links/dedupeLink.ts +1 -2
  52. package/src/links/httpBatchLink.ts +2 -2
  53. package/src/links/httpLink.ts +2 -2
  54. package/src/links/internals/createChain.test.ts +1 -1
  55. package/src/links/loggerLink.ts +1 -2
  56. package/src/links/splitLink.test.ts +2 -2
  57. package/src/links/splitLink.ts +2 -2
  58. package/src/observable/observable.test.ts +1 -3
@@ -0,0 +1,210 @@
1
+ import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
2
+ import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/transformRPCResponse-f7f8b0e1.esm.js';
3
+ import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
4
+ import '@babel/runtime/helpers/createClass';
5
+ import '@babel/runtime/helpers/classCallCheck';
6
+ import '@babel/runtime/helpers/assertThisInitialized';
7
+ import '@babel/runtime/helpers/inherits';
8
+ import '@babel/runtime/helpers/createSuper';
9
+ import '@babel/runtime/helpers/wrapNativeSuper';
10
+ import '@babel/runtime/helpers/objectSpread2';
11
+
12
+ /**
13
+ * Dataloader that's very inspired by https://github.com/graphql/dataloader
14
+ * Less configuration, no caching, and allows you to cancel requests
15
+ * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
16
+ */
17
+ function dataLoader(fetchMany, opts) {
18
+ var batch = null;
19
+ var dispatchTimer = null;
20
+
21
+ var destroyTimerAndBatch = function destroyTimerAndBatch() {
22
+ clearTimeout(dispatchTimer);
23
+ dispatchTimer = null;
24
+ batch = null;
25
+ };
26
+
27
+ function dispatch() {
28
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
29
+ var batchCopy = batch;
30
+ destroyTimerAndBatch();
31
+
32
+ var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
33
+ return v.key;
34
+ })),
35
+ promise = _fetchMany.promise,
36
+ cancel = _fetchMany.cancel;
37
+
38
+ batchCopy.cancel = cancel;
39
+ promise.then(function (result) {
40
+ for (var i = 0; i < result.length; i++) {
41
+ var _value = result[i];
42
+ batchCopy.items[i].resolve(_value);
43
+ }
44
+ }).catch(function (cause) {
45
+ var _iterator = _createForOfIteratorHelper(batchCopy.items),
46
+ _step;
47
+
48
+ try {
49
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
50
+ var item = _step.value;
51
+ item.reject(cause);
52
+ }
53
+ } catch (err) {
54
+ _iterator.e(err);
55
+ } finally {
56
+ _iterator.f();
57
+ }
58
+ });
59
+ }
60
+
61
+ function load(key) {
62
+ var batchItem = {
63
+ cancelled: false,
64
+ key: key
65
+ };
66
+
67
+ if (!batch) {
68
+ batch = {
69
+ items: [],
70
+ cancel: function cancel() {
71
+ destroyTimerAndBatch();
72
+ }
73
+ };
74
+ }
75
+
76
+ var thisBatch = batch;
77
+ var promise = new Promise(function (resolve, reject) {
78
+ var item = batchItem;
79
+ item.reject = reject;
80
+ item.resolve = resolve;
81
+ thisBatch.items.push(item);
82
+
83
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
84
+ dispatch();
85
+ return;
86
+ }
87
+ });
88
+
89
+ if (!dispatchTimer) {
90
+ dispatchTimer = setTimeout(dispatch);
91
+ }
92
+
93
+ var cancel = function cancel() {
94
+ batchItem.cancelled = true;
95
+
96
+ if (thisBatch.items.some(function (item) {
97
+ return !item.cancelled;
98
+ })) {
99
+ // there are still things that can be resolved
100
+ return;
101
+ }
102
+
103
+ thisBatch.cancel();
104
+ };
105
+
106
+ return {
107
+ promise: promise,
108
+ cancel: cancel
109
+ };
110
+ }
111
+
112
+ return {
113
+ load: load
114
+ };
115
+ }
116
+
117
+ function httpBatchLink(opts) {
118
+ var url = opts.url,
119
+ maxBatchSize = opts.maxBatchSize; // initialized config
120
+
121
+ return function (runtime) {
122
+ // initialized in app
123
+ var fetcher = function fetcher(type) {
124
+ return function (keyInputPairs) {
125
+ var path = keyInputPairs.map(function (op) {
126
+ return op.path;
127
+ }).join(',');
128
+ var inputs = keyInputPairs.map(function (op) {
129
+ return op.input;
130
+ });
131
+
132
+ var _httpRequest = httpRequest({
133
+ url: url,
134
+ inputs: inputs,
135
+ path: path,
136
+ runtime: runtime,
137
+ type: type
138
+ }),
139
+ promise = _httpRequest.promise,
140
+ cancel = _httpRequest.cancel;
141
+
142
+ return {
143
+ promise: promise.then(function (res) {
144
+ if (!Array.isArray(res)) {
145
+ return keyInputPairs.map(function () {
146
+ return res;
147
+ });
148
+ }
149
+
150
+ return res;
151
+ }),
152
+ cancel: cancel
153
+ };
154
+ };
155
+ };
156
+
157
+ var query = dataLoader(fetcher('query'), {
158
+ maxBatchSize: maxBatchSize
159
+ });
160
+ var mutation = dataLoader(fetcher('mutation'), {
161
+ maxBatchSize: maxBatchSize
162
+ });
163
+ var subscription = dataLoader(fetcher('subscription'), {
164
+ maxBatchSize: maxBatchSize
165
+ });
166
+ var loaders = {
167
+ query: query,
168
+ subscription: subscription,
169
+ mutation: mutation
170
+ };
171
+ return function (_ref) {
172
+ var op = _ref.op,
173
+ prev = _ref.prev,
174
+ onDestroy = _ref.onDestroy;
175
+ var loader = loaders[op.type];
176
+
177
+ var _loader$load = loader.load(op),
178
+ promise = _loader$load.promise,
179
+ cancel = _loader$load.cancel;
180
+
181
+ var isDone = false;
182
+
183
+ var prevOnce = function prevOnce(result) {
184
+ if (isDone) {
185
+ return;
186
+ }
187
+
188
+ isDone = true;
189
+ prev(result);
190
+ };
191
+
192
+ onDestroy(function () {
193
+ prevOnce(TRPCClientError.from(new TRPCAbortError(), {
194
+ isDone: true
195
+ }));
196
+ cancel();
197
+ });
198
+ promise.then(function (envelope) {
199
+ prevOnce(transformRPCResponse({
200
+ envelope: envelope,
201
+ runtime: runtime
202
+ }));
203
+ }).catch(function (cause) {
204
+ prevOnce(TRPCClientError.from(cause));
205
+ });
206
+ };
207
+ };
208
+ }
209
+
210
+ export { httpBatchLink };
@@ -1,11 +1 @@
1
- // are you seeing an error that a default export doesn't exist but your source file has a default export?
2
- // you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
3
-
4
- // curious why you need to?
5
- // this file exists so that you can import from the entrypoint normally
6
- // except that it points to your source file and you don't need to run build constantly
7
- // which means we need to re-export all of the modules from your source file
8
- // and since export * doesn't include default exports, we need to read your source file
9
- // to check for a default export and re-export it if it exists
10
- // it's not ideal, but it works pretty well ¯\_(ツ)_/¯
11
- export * from "../../../src/links/httpLink";
1
+ export * from "../../../dist/declarations/src/links/httpLink";
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
6
+ var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
7
+ require('@babel/runtime/helpers/objectSpread2');
8
+ require('@babel/runtime/helpers/classCallCheck');
9
+ require('@babel/runtime/helpers/createClass');
10
+ require('@babel/runtime/helpers/assertThisInitialized');
11
+ require('@babel/runtime/helpers/inherits');
12
+ require('@babel/runtime/helpers/createSuper');
13
+ require('@babel/runtime/helpers/wrapNativeSuper');
14
+
15
+ function httpLink(opts) {
16
+ var url = opts.url; // initialized config
17
+
18
+ return function (runtime) {
19
+ // initialized in app
20
+ return function (_ref) {
21
+ var op = _ref.op,
22
+ prev = _ref.prev,
23
+ onDestroy = _ref.onDestroy;
24
+ var path = op.path,
25
+ input = op.input,
26
+ type = op.type;
27
+
28
+ var _httpRequest = transformRPCResponse.httpRequest({
29
+ runtime: runtime,
30
+ type: type,
31
+ input: input,
32
+ url: url,
33
+ path: path
34
+ }),
35
+ promise = _httpRequest.promise,
36
+ cancel = _httpRequest.cancel;
37
+
38
+ var isDone = false;
39
+
40
+ var prevOnce = function prevOnce(result) {
41
+ if (isDone) {
42
+ return;
43
+ }
44
+
45
+ isDone = true;
46
+ prev(result);
47
+ };
48
+
49
+ onDestroy(function () {
50
+ prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
51
+ isDone: true
52
+ }));
53
+ cancel();
54
+ });
55
+ promise.then(function (envelope) {
56
+ prevOnce(transformRPCResponse.transformRPCResponse({
57
+ envelope: envelope,
58
+ runtime: runtime
59
+ }));
60
+ }).catch(function (cause) {
61
+ prevOnce(TRPCClientError.TRPCClientError.from(cause));
62
+ });
63
+ };
64
+ };
65
+ }
66
+
67
+ exports.httpLink = httpLink;
@@ -1,16 +1,7 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
1
+ 'use strict';
9
2
 
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../../../src/links/httpLink.ts");
15
-
16
- unregister();
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./trpc-client-links-httpLink.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./trpc-client-links-httpLink.cjs.dev.js");
7
+ }
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
6
+ var transformRPCResponse = require('../../../dist/transformRPCResponse-739c13d0.cjs.prod.js');
7
+ require('@babel/runtime/helpers/objectSpread2');
8
+ require('@babel/runtime/helpers/classCallCheck');
9
+ require('@babel/runtime/helpers/createClass');
10
+ require('@babel/runtime/helpers/assertThisInitialized');
11
+ require('@babel/runtime/helpers/inherits');
12
+ require('@babel/runtime/helpers/createSuper');
13
+ require('@babel/runtime/helpers/wrapNativeSuper');
14
+
15
+ function httpLink(opts) {
16
+ var url = opts.url; // initialized config
17
+
18
+ return function (runtime) {
19
+ // initialized in app
20
+ return function (_ref) {
21
+ var op = _ref.op,
22
+ prev = _ref.prev,
23
+ onDestroy = _ref.onDestroy;
24
+ var path = op.path,
25
+ input = op.input,
26
+ type = op.type;
27
+
28
+ var _httpRequest = transformRPCResponse.httpRequest({
29
+ runtime: runtime,
30
+ type: type,
31
+ input: input,
32
+ url: url,
33
+ path: path
34
+ }),
35
+ promise = _httpRequest.promise,
36
+ cancel = _httpRequest.cancel;
37
+
38
+ var isDone = false;
39
+
40
+ var prevOnce = function prevOnce(result) {
41
+ if (isDone) {
42
+ return;
43
+ }
44
+
45
+ isDone = true;
46
+ prev(result);
47
+ };
48
+
49
+ onDestroy(function () {
50
+ prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
51
+ isDone: true
52
+ }));
53
+ cancel();
54
+ });
55
+ promise.then(function (envelope) {
56
+ prevOnce(transformRPCResponse.transformRPCResponse({
57
+ envelope: envelope,
58
+ runtime: runtime
59
+ }));
60
+ }).catch(function (cause) {
61
+ prevOnce(TRPCClientError.TRPCClientError.from(cause));
62
+ });
63
+ };
64
+ };
65
+ }
66
+
67
+ exports.httpLink = httpLink;
@@ -0,0 +1,63 @@
1
+ import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
2
+ import { h as httpRequest, T as TRPCAbortError, t as transformRPCResponse } from '../../../dist/transformRPCResponse-f7f8b0e1.esm.js';
3
+ import '@babel/runtime/helpers/objectSpread2';
4
+ import '@babel/runtime/helpers/classCallCheck';
5
+ import '@babel/runtime/helpers/createClass';
6
+ import '@babel/runtime/helpers/assertThisInitialized';
7
+ import '@babel/runtime/helpers/inherits';
8
+ import '@babel/runtime/helpers/createSuper';
9
+ import '@babel/runtime/helpers/wrapNativeSuper';
10
+
11
+ function httpLink(opts) {
12
+ var url = opts.url; // initialized config
13
+
14
+ return function (runtime) {
15
+ // initialized in app
16
+ return function (_ref) {
17
+ var op = _ref.op,
18
+ prev = _ref.prev,
19
+ onDestroy = _ref.onDestroy;
20
+ var path = op.path,
21
+ input = op.input,
22
+ type = op.type;
23
+
24
+ var _httpRequest = httpRequest({
25
+ runtime: runtime,
26
+ type: type,
27
+ input: input,
28
+ url: url,
29
+ path: path
30
+ }),
31
+ promise = _httpRequest.promise,
32
+ cancel = _httpRequest.cancel;
33
+
34
+ var isDone = false;
35
+
36
+ var prevOnce = function prevOnce(result) {
37
+ if (isDone) {
38
+ return;
39
+ }
40
+
41
+ isDone = true;
42
+ prev(result);
43
+ };
44
+
45
+ onDestroy(function () {
46
+ prevOnce(TRPCClientError.from(new TRPCAbortError(), {
47
+ isDone: true
48
+ }));
49
+ cancel();
50
+ });
51
+ promise.then(function (envelope) {
52
+ prevOnce(transformRPCResponse({
53
+ envelope: envelope,
54
+ runtime: runtime
55
+ }));
56
+ }).catch(function (cause) {
57
+ prevOnce(TRPCClientError.from(cause));
58
+ });
59
+ };
60
+ };
61
+ }
62
+
63
+ export { httpLink };
@@ -1,11 +1 @@
1
- // are you seeing an error that a default export doesn't exist but your source file has a default export?
2
- // you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
3
-
4
- // curious why you need to?
5
- // this file exists so that you can import from the entrypoint normally
6
- // except that it points to your source file and you don't need to run build constantly
7
- // which means we need to re-export all of the modules from your source file
8
- // and since export * doesn't include default exports, we need to read your source file
9
- // to check for a default export and re-export it if it exists
10
- // it's not ideal, but it works pretty well ¯\_(ツ)_/¯
11
- export * from "../../../src/links/loggerLink";
1
+ export * from "../../../dist/declarations/src/links/loggerLink";
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
+
8
+ var palette = {
9
+ query: ['72e3ff', '3fb0d8'],
10
+ mutation: ['c5a3fc', '904dfc'],
11
+ subscription: ['ff49e1', 'd83fbe']
12
+ };
13
+
14
+ // maybe this should be moved to it's own package
15
+ var defaultLogger = function defaultLogger() {
16
+ var c = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : console;
17
+ return function (props) {
18
+ var direction = props.direction,
19
+ input = props.input,
20
+ type = props.type,
21
+ path = props.path,
22
+ context = props.context,
23
+ id = props.id;
24
+
25
+ var _palette$type = _slicedToArray(palette[type], 2),
26
+ light = _palette$type[0],
27
+ dark = _palette$type[1];
28
+
29
+ var css = "\n background-color: #".concat(direction === 'up' ? light : dark, "; \n color: ").concat(direction === 'up' ? 'black' : 'white', ";\n padding: 2px;\n ");
30
+ var parts = ['%c', direction === 'up' ? '>>' : '<<', type, "#".concat(id), "%c".concat(path, "%c"), '%O'];
31
+ var args = [css, "".concat(css, "; font-weight: bold;"), "".concat(css, "; font-weight: normal;")];
32
+
33
+ if (props.direction === 'up') {
34
+ args.push({
35
+ input: input,
36
+ context: context
37
+ });
38
+ } else {
39
+ args.push({
40
+ input: input,
41
+ result: props.result,
42
+ elapsedMs: props.elapsedMs,
43
+ context: context
44
+ });
45
+ }
46
+
47
+ var fn = props.direction === 'down' && props.result && props.result instanceof Error ? 'error' : 'log';
48
+ c[fn].apply(null, [parts.join(' ')].concat(args));
49
+ };
50
+ };
51
+
52
+ function loggerLink() {
53
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
54
+ var _opts$enabled = opts.enabled,
55
+ enabled = _opts$enabled === void 0 ? function () {
56
+ return true;
57
+ } : _opts$enabled;
58
+ var _opts$logger = opts.logger,
59
+ logger = _opts$logger === void 0 ? defaultLogger(opts.console) : _opts$logger;
60
+ return function () {
61
+ return function (_ref) {
62
+ var op = _ref.op,
63
+ next = _ref.next,
64
+ prev = _ref.prev;
65
+ // ->
66
+ enabled(_objectSpread(_objectSpread({}, op), {}, {
67
+ direction: 'up'
68
+ })) && logger(_objectSpread(_objectSpread({}, op), {}, {
69
+ direction: 'up'
70
+ }));
71
+ var requestStartTime = Date.now();
72
+ next(op, function (result) {
73
+ var elapsedMs = Date.now() - requestStartTime;
74
+ enabled(_objectSpread(_objectSpread({}, op), {}, {
75
+ direction: 'down',
76
+ result: result
77
+ })) && logger(_objectSpread(_objectSpread({}, op), {}, {
78
+ direction: 'down',
79
+ elapsedMs: elapsedMs,
80
+ result: result
81
+ })); // <-
82
+
83
+ prev(result);
84
+ });
85
+ };
86
+ };
87
+ }
88
+
89
+ exports.loggerLink = loggerLink;
@@ -1,16 +1,7 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
1
+ 'use strict';
9
2
 
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../../../src/links/loggerLink.ts");
15
-
16
- unregister();
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./trpc-client-links-loggerLink.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./trpc-client-links-loggerLink.cjs.dev.js");
7
+ }
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
+
8
+ var palette = {
9
+ query: ['72e3ff', '3fb0d8'],
10
+ mutation: ['c5a3fc', '904dfc'],
11
+ subscription: ['ff49e1', 'd83fbe']
12
+ };
13
+
14
+ // maybe this should be moved to it's own package
15
+ var defaultLogger = function defaultLogger() {
16
+ var c = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : console;
17
+ return function (props) {
18
+ var direction = props.direction,
19
+ input = props.input,
20
+ type = props.type,
21
+ path = props.path,
22
+ context = props.context,
23
+ id = props.id;
24
+
25
+ var _palette$type = _slicedToArray(palette[type], 2),
26
+ light = _palette$type[0],
27
+ dark = _palette$type[1];
28
+
29
+ var css = "\n background-color: #".concat(direction === 'up' ? light : dark, "; \n color: ").concat(direction === 'up' ? 'black' : 'white', ";\n padding: 2px;\n ");
30
+ var parts = ['%c', direction === 'up' ? '>>' : '<<', type, "#".concat(id), "%c".concat(path, "%c"), '%O'];
31
+ var args = [css, "".concat(css, "; font-weight: bold;"), "".concat(css, "; font-weight: normal;")];
32
+
33
+ if (props.direction === 'up') {
34
+ args.push({
35
+ input: input,
36
+ context: context
37
+ });
38
+ } else {
39
+ args.push({
40
+ input: input,
41
+ result: props.result,
42
+ elapsedMs: props.elapsedMs,
43
+ context: context
44
+ });
45
+ }
46
+
47
+ var fn = props.direction === 'down' && props.result && props.result instanceof Error ? 'error' : 'log';
48
+ c[fn].apply(null, [parts.join(' ')].concat(args));
49
+ };
50
+ };
51
+
52
+ function loggerLink() {
53
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
54
+ var _opts$enabled = opts.enabled,
55
+ enabled = _opts$enabled === void 0 ? function () {
56
+ return true;
57
+ } : _opts$enabled;
58
+ var _opts$logger = opts.logger,
59
+ logger = _opts$logger === void 0 ? defaultLogger(opts.console) : _opts$logger;
60
+ return function () {
61
+ return function (_ref) {
62
+ var op = _ref.op,
63
+ next = _ref.next,
64
+ prev = _ref.prev;
65
+ // ->
66
+ enabled(_objectSpread(_objectSpread({}, op), {}, {
67
+ direction: 'up'
68
+ })) && logger(_objectSpread(_objectSpread({}, op), {}, {
69
+ direction: 'up'
70
+ }));
71
+ var requestStartTime = Date.now();
72
+ next(op, function (result) {
73
+ var elapsedMs = Date.now() - requestStartTime;
74
+ enabled(_objectSpread(_objectSpread({}, op), {}, {
75
+ direction: 'down',
76
+ result: result
77
+ })) && logger(_objectSpread(_objectSpread({}, op), {}, {
78
+ direction: 'down',
79
+ elapsedMs: elapsedMs,
80
+ result: result
81
+ })); // <-
82
+
83
+ prev(result);
84
+ });
85
+ };
86
+ };
87
+ }
88
+
89
+ exports.loggerLink = loggerLink;