@demokit-ai/trpc 0.2.0 → 0.3.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/LICENSE +190 -0
- package/dist/chunk-2C4EOFRK.js +277 -0
- package/dist/chunk-2C4EOFRK.js.map +1 -0
- package/dist/index.cjs +52 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -267
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +68 -25
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +28 -215
- package/dist/react.js.map +1 -1
- package/package.json +23 -46
- package/README.md +0 -203
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 Kasava, Inc.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// src/fixtures.ts
|
|
2
|
+
function defineTRPCFixtures() {
|
|
3
|
+
return function(fixtures) {
|
|
4
|
+
return fixtures;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
function defineFixtureMap(fixtures) {
|
|
8
|
+
return new Map(Object.entries(fixtures));
|
|
9
|
+
}
|
|
10
|
+
function createFixtureHandler(handler) {
|
|
11
|
+
return handler;
|
|
12
|
+
}
|
|
13
|
+
function normalizeFixtures(fixtures) {
|
|
14
|
+
if (!fixtures) {
|
|
15
|
+
return /* @__PURE__ */ new Map();
|
|
16
|
+
}
|
|
17
|
+
if (fixtures instanceof Map) {
|
|
18
|
+
return fixtures;
|
|
19
|
+
}
|
|
20
|
+
const result = /* @__PURE__ */ new Map();
|
|
21
|
+
function flatten(obj, prefix = "") {
|
|
22
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
23
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
24
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && typeof value !== "function") {
|
|
25
|
+
const hasNestedProcedures = Object.values(value).some(
|
|
26
|
+
(v) => typeof v === "function" || Array.isArray(v) || typeof v === "object" && v !== null
|
|
27
|
+
);
|
|
28
|
+
if (hasNestedProcedures) {
|
|
29
|
+
flatten(value, path);
|
|
30
|
+
} else {
|
|
31
|
+
result.set(path, value);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
result.set(path, value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
flatten(fixtures);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/matcher.ts
|
|
43
|
+
function findMatchingFixture(fixtures, path) {
|
|
44
|
+
const handler = fixtures.get(path);
|
|
45
|
+
if (handler !== void 0) {
|
|
46
|
+
return {
|
|
47
|
+
matched: true,
|
|
48
|
+
handler,
|
|
49
|
+
path
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
matched: false,
|
|
54
|
+
path
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function shouldIntercept(path, include, exclude) {
|
|
58
|
+
if (exclude?.includes(path)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
if (include && include.length > 0) {
|
|
62
|
+
return include.includes(path);
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function matchPath(path, pattern) {
|
|
67
|
+
if (pattern === "*") {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (pattern === path) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
if (pattern.includes("*")) {
|
|
74
|
+
const regex = new RegExp(
|
|
75
|
+
"^" + pattern.split("*").map((s) => escapeRegex(s)).join(".*") + "$"
|
|
76
|
+
);
|
|
77
|
+
return regex.test(path);
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
function escapeRegex(str) {
|
|
82
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
83
|
+
}
|
|
84
|
+
function filterFixtures(fixtures, include, exclude) {
|
|
85
|
+
const result = /* @__PURE__ */ new Map();
|
|
86
|
+
for (const [path, handler] of fixtures) {
|
|
87
|
+
let shouldInclude = true;
|
|
88
|
+
if (include && include.length > 0) {
|
|
89
|
+
shouldInclude = include.some((pattern) => matchPath(path, pattern));
|
|
90
|
+
}
|
|
91
|
+
if (exclude && exclude.length > 0) {
|
|
92
|
+
if (exclude.some((pattern) => matchPath(path, pattern))) {
|
|
93
|
+
shouldInclude = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (shouldInclude) {
|
|
97
|
+
result.set(path, handler);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
function getFixturePaths(fixtures) {
|
|
103
|
+
return Array.from(fixtures.keys());
|
|
104
|
+
}
|
|
105
|
+
function mergeFixtures(...maps) {
|
|
106
|
+
const result = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const map of maps) {
|
|
108
|
+
for (const [path, handler] of map) {
|
|
109
|
+
result.set(path, handler);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// src/link.ts
|
|
116
|
+
import { observable } from "@trpc/server/observable";
|
|
117
|
+
function createDemoLink(options = {}) {
|
|
118
|
+
const {
|
|
119
|
+
fixtures: rawFixtures,
|
|
120
|
+
isEnabled = () => false,
|
|
121
|
+
delay = 0,
|
|
122
|
+
include,
|
|
123
|
+
exclude,
|
|
124
|
+
onMissing
|
|
125
|
+
} = options;
|
|
126
|
+
const fixtures = normalizeFixtures(rawFixtures);
|
|
127
|
+
return () => {
|
|
128
|
+
return ({ next, op }) => {
|
|
129
|
+
return observable((observer) => {
|
|
130
|
+
if (!isEnabled()) {
|
|
131
|
+
const unsubscribe = next(op).subscribe({
|
|
132
|
+
next(value) {
|
|
133
|
+
observer.next(value);
|
|
134
|
+
},
|
|
135
|
+
error(err) {
|
|
136
|
+
observer.error(err);
|
|
137
|
+
},
|
|
138
|
+
complete() {
|
|
139
|
+
observer.complete();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return unsubscribe;
|
|
143
|
+
}
|
|
144
|
+
if (!shouldIntercept(op.path, include, exclude)) {
|
|
145
|
+
const unsubscribe = next(op).subscribe({
|
|
146
|
+
next(value) {
|
|
147
|
+
observer.next(value);
|
|
148
|
+
},
|
|
149
|
+
error(err) {
|
|
150
|
+
observer.error(err);
|
|
151
|
+
},
|
|
152
|
+
complete() {
|
|
153
|
+
observer.complete();
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return unsubscribe;
|
|
157
|
+
}
|
|
158
|
+
const match = findMatchingFixture(fixtures, op.path);
|
|
159
|
+
if (!match.matched || !match.handler) {
|
|
160
|
+
onMissing?.(op.path, op.input);
|
|
161
|
+
const unsubscribe = next(op).subscribe({
|
|
162
|
+
next(value) {
|
|
163
|
+
observer.next(value);
|
|
164
|
+
},
|
|
165
|
+
error(err) {
|
|
166
|
+
observer.error(err);
|
|
167
|
+
},
|
|
168
|
+
complete() {
|
|
169
|
+
observer.complete();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return unsubscribe;
|
|
173
|
+
}
|
|
174
|
+
const executeFixture = async () => {
|
|
175
|
+
const context = {
|
|
176
|
+
path: op.path,
|
|
177
|
+
input: op.input,
|
|
178
|
+
type: op.type
|
|
179
|
+
};
|
|
180
|
+
if (delay > 0) {
|
|
181
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
182
|
+
}
|
|
183
|
+
const handler = match.handler;
|
|
184
|
+
const result = typeof handler === "function" ? await handler(context) : handler;
|
|
185
|
+
return result;
|
|
186
|
+
};
|
|
187
|
+
executeFixture().then((data) => {
|
|
188
|
+
observer.next({
|
|
189
|
+
result: { data }
|
|
190
|
+
});
|
|
191
|
+
observer.complete();
|
|
192
|
+
}).catch((err) => {
|
|
193
|
+
observer.error(err);
|
|
194
|
+
});
|
|
195
|
+
return () => {
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function createDemoLinkWithState(options = {}) {
|
|
202
|
+
const { fixtures: rawFixtures, enabled: initialEnabled = false, ...rest } = options;
|
|
203
|
+
let enabled = initialEnabled;
|
|
204
|
+
const fixtures = normalizeFixtures(rawFixtures);
|
|
205
|
+
const link = createDemoLink({
|
|
206
|
+
...rest,
|
|
207
|
+
fixtures,
|
|
208
|
+
isEnabled: () => enabled
|
|
209
|
+
});
|
|
210
|
+
return {
|
|
211
|
+
/**
|
|
212
|
+
* The tRPC link to use in your client
|
|
213
|
+
*/
|
|
214
|
+
link,
|
|
215
|
+
/**
|
|
216
|
+
* Enable demo mode
|
|
217
|
+
*/
|
|
218
|
+
enable: () => {
|
|
219
|
+
enabled = true;
|
|
220
|
+
},
|
|
221
|
+
/**
|
|
222
|
+
* Disable demo mode
|
|
223
|
+
*/
|
|
224
|
+
disable: () => {
|
|
225
|
+
enabled = false;
|
|
226
|
+
},
|
|
227
|
+
/**
|
|
228
|
+
* Check if demo mode is enabled
|
|
229
|
+
*/
|
|
230
|
+
isEnabled: () => enabled,
|
|
231
|
+
/**
|
|
232
|
+
* Toggle demo mode
|
|
233
|
+
*/
|
|
234
|
+
toggle: () => {
|
|
235
|
+
enabled = !enabled;
|
|
236
|
+
return enabled;
|
|
237
|
+
},
|
|
238
|
+
/**
|
|
239
|
+
* Set or update a fixture
|
|
240
|
+
*/
|
|
241
|
+
setFixture: (path, handler) => {
|
|
242
|
+
fixtures.set(path, handler);
|
|
243
|
+
},
|
|
244
|
+
/**
|
|
245
|
+
* Remove a fixture
|
|
246
|
+
*/
|
|
247
|
+
removeFixture: (path) => {
|
|
248
|
+
fixtures.delete(path);
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* Get all fixtures
|
|
252
|
+
*/
|
|
253
|
+
getFixtures: () => fixtures,
|
|
254
|
+
/**
|
|
255
|
+
* Clear all fixtures
|
|
256
|
+
*/
|
|
257
|
+
clearFixtures: () => {
|
|
258
|
+
fixtures.clear();
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export {
|
|
264
|
+
defineTRPCFixtures,
|
|
265
|
+
defineFixtureMap,
|
|
266
|
+
createFixtureHandler,
|
|
267
|
+
normalizeFixtures,
|
|
268
|
+
findMatchingFixture,
|
|
269
|
+
shouldIntercept,
|
|
270
|
+
matchPath,
|
|
271
|
+
filterFixtures,
|
|
272
|
+
getFixturePaths,
|
|
273
|
+
mergeFixtures,
|
|
274
|
+
createDemoLink,
|
|
275
|
+
createDemoLinkWithState
|
|
276
|
+
};
|
|
277
|
+
//# sourceMappingURL=chunk-2C4EOFRK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/fixtures.ts","../src/matcher.ts","../src/link.ts"],"sourcesContent":["import type {\n AnyRouter,\n inferRouterInputs,\n inferRouterOutputs,\n} from '@trpc/server'\nimport type { TRPCFixtureHandler, TRPCFixtureContext, FlatFixtureMap } from './types'\n\n/**\n * Type helper to create fixture handlers with full type inference\n *\n * This helper infers input/output types from your router definition,\n * providing autocomplete and type checking for fixture definitions.\n *\n * @example\n * import { defineTRPCFixtures } from '@demokit-ai/trpc'\n * import type { AppRouter } from '../server/router'\n *\n * // Nested structure matching your router\n * const fixtures = defineTRPCFixtures<AppRouter>()({\n * user: {\n * list: () => [\n * { id: '1', name: 'Demo User', email: 'demo@example.com' }\n * ],\n * get: ({ input }) => ({\n * id: input.id,\n * name: 'Demo User',\n * email: 'demo@example.com',\n * }),\n * create: async ({ input }) => ({\n * id: crypto.randomUUID(),\n * ...input,\n * createdAt: new Date(),\n * }),\n * },\n * post: {\n * list: () => [],\n * },\n * })\n */\nexport function defineTRPCFixtures<TRouter extends AnyRouter>() {\n type RouterIn = inferRouterInputs<TRouter>\n type RouterOut = inferRouterOutputs<TRouter>\n\n /**\n * Helper type to build nested fixture structure\n */\n type BuildFixtureType<TIn, TOut> = {\n [K in keyof TIn & keyof TOut]?: TIn[K] extends object\n ? TOut[K] extends object\n ? // Check if this is a procedure (has no nested keys) or a namespace\n keyof TIn[K] extends never\n ? TRPCFixtureHandler<TIn[K], TOut[K]>\n : BuildFixtureType<TIn[K], TOut[K]>\n : TRPCFixtureHandler<TIn[K], TOut[K]>\n : TRPCFixtureHandler<TIn[K], TOut[K]>\n }\n\n return function <T extends BuildFixtureType<RouterIn, RouterOut>>(fixtures: T): T {\n return fixtures\n }\n}\n\n/**\n * Alternative: define fixtures using flat dot-notation paths\n *\n * Useful when you want to define fixtures independently of router structure.\n *\n * @example\n * const fixtures = defineFixtureMap<AppRouter>({\n * 'user.list': () => [{ id: '1', name: 'Demo' }],\n * 'user.get': ({ input }) => ({ id: input.id, name: 'Demo' }),\n * })\n */\nexport function defineFixtureMap<TRouter extends AnyRouter>(\n fixtures: FlatFixtureRecord<TRouter>\n): FlatFixtureMap {\n return new Map(Object.entries(fixtures))\n}\n\n/**\n * Type for flat fixture map with path-based keys\n */\ntype FlatFixtureRecord<TRouter extends AnyRouter> = {\n [K in ProcedurePaths<TRouter>]?: TRPCFixtureHandler<\n PathInput<TRouter, K>,\n PathOutput<TRouter, K>\n >\n}\n\n/**\n * Extract all procedure paths from a router using dot notation\n */\ntype ProcedurePaths<TRouter extends AnyRouter> = inferRouterInputs<TRouter> extends infer TIn\n ? TIn extends object\n ? FlattenPaths<TIn>\n : never\n : never\n\n/**\n * Flatten nested object keys to dot notation\n */\ntype FlattenPaths<T, Prefix extends string = ''> = T extends object\n ? {\n [K in keyof T]: K extends string\n ? T[K] extends object\n ? keyof T[K] extends never\n ? `${Prefix}${K}`\n : FlattenPaths<T[K], `${Prefix}${K}.`>\n : `${Prefix}${K}`\n : never\n }[keyof T]\n : never\n\n/**\n * Get input type for a specific procedure path\n */\ntype PathInput<TRouter extends AnyRouter, Path extends string> = Path extends `${infer First}.${infer Rest}`\n ? inferRouterInputs<TRouter>[First] extends object\n ? PathInput<inferRouterInputs<TRouter>[First] extends AnyRouter ? inferRouterInputs<TRouter>[First] : never, Rest>\n : never\n : inferRouterInputs<TRouter>[Path]\n\n/**\n * Get output type for a specific procedure path\n */\ntype PathOutput<TRouter extends AnyRouter, Path extends string> = Path extends `${infer First}.${infer Rest}`\n ? inferRouterOutputs<TRouter>[First] extends object\n ? PathOutput<inferRouterOutputs<TRouter>[First] extends AnyRouter ? inferRouterOutputs<TRouter>[First] : never, Rest>\n : never\n : inferRouterOutputs<TRouter>[Path]\n\n/**\n * Create a fixture handler with explicit types\n *\n * Useful when you need to define a fixture outside of the main fixture object.\n *\n * @example\n * const getUserFixture = createFixtureHandler<{ id: string }, User>(\n * ({ input }) => ({\n * id: input.id,\n * name: 'Demo User',\n * })\n * )\n */\nexport function createFixtureHandler<TInput, TOutput>(\n handler: TRPCFixtureHandler<TInput, TOutput>\n): TRPCFixtureHandler<TInput, TOutput> {\n return handler\n}\n\n/**\n * Normalize fixture definitions to a flat Map\n *\n * Converts nested fixture objects to a flat map with dot-notation paths.\n */\nexport function normalizeFixtures(\n fixtures: Record<string, unknown> | FlatFixtureMap | undefined\n): FlatFixtureMap {\n if (!fixtures) {\n return new Map()\n }\n\n if (fixtures instanceof Map) {\n return fixtures\n }\n\n const result: FlatFixtureMap = new Map()\n\n function flatten(obj: Record<string, unknown>, prefix = '') {\n for (const [key, value] of Object.entries(obj)) {\n const path = prefix ? `${prefix}.${key}` : key\n\n if (\n value !== null &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n typeof value !== 'function'\n ) {\n // Check if this looks like a fixture handler or a namespace\n // Fixture handlers are either primitives, arrays, or functions\n // Namespaces are objects with nested procedures\n const hasNestedProcedures = Object.values(value).some(\n (v) => typeof v === 'function' || Array.isArray(v) || (typeof v === 'object' && v !== null)\n )\n\n if (hasNestedProcedures) {\n flatten(value as Record<string, unknown>, path)\n } else {\n // This is a static fixture value (an object)\n result.set(path, value as TRPCFixtureHandler)\n }\n } else {\n // This is a fixture handler (function, array, or primitive)\n result.set(path, value as TRPCFixtureHandler)\n }\n }\n }\n\n flatten(fixtures as Record<string, unknown>)\n return result\n}\n","import type { FlatFixtureMap, TRPCFixtureHandler, FixtureMatchResult } from './types'\n\n/**\n * Find a matching fixture for a procedure path\n *\n * @param fixtures - Map of procedure paths to fixture handlers\n * @param path - The procedure path to match (e.g., 'user.get', 'post.list')\n * @returns Match result with handler if found\n *\n * @example\n * const fixtures = new Map([\n * ['user.list', () => []],\n * ['user.get', ({ input }) => ({ id: input.id })],\n * ])\n *\n * findMatchingFixture(fixtures, 'user.get')\n * // { matched: true, handler: Function, path: 'user.get' }\n *\n * findMatchingFixture(fixtures, 'unknown.path')\n * // { matched: false, path: 'unknown.path' }\n */\nexport function findMatchingFixture<TOutput = unknown>(\n fixtures: FlatFixtureMap,\n path: string\n): FixtureMatchResult<TOutput> {\n const handler = fixtures.get(path)\n\n if (handler !== undefined) {\n return {\n matched: true,\n handler: handler as TRPCFixtureHandler<unknown, TOutput>,\n path,\n }\n }\n\n return {\n matched: false,\n path,\n }\n}\n\n/**\n * Check if a procedure path should be intercepted based on include/exclude rules\n *\n * @param path - The procedure path to check\n * @param include - Optional list of paths to include (if provided, only these are intercepted)\n * @param exclude - Optional list of paths to exclude (takes precedence over include)\n * @returns Whether the path should be intercepted\n *\n * @example\n * // Include only specific paths\n * shouldIntercept('user.get', ['user.get', 'user.list'], [])\n * // true\n *\n * shouldIntercept('post.list', ['user.get', 'user.list'], [])\n * // false\n *\n * // Exclude takes precedence\n * shouldIntercept('user.get', ['user.get'], ['user.get'])\n * // false\n */\nexport function shouldIntercept(\n path: string,\n include?: string[],\n exclude?: string[]\n): boolean {\n // Exclude takes precedence\n if (exclude?.includes(path)) {\n return false\n }\n\n // If include list is provided, only intercept those\n if (include && include.length > 0) {\n return include.includes(path)\n }\n\n // By default, intercept all\n return true\n}\n\n/**\n * Check if a procedure path matches a pattern with wildcards\n *\n * Supports:\n * - Exact match: 'user.get' matches 'user.get'\n * - Wildcard suffix: 'user.*' matches 'user.get', 'user.list', etc.\n * - Wildcard prefix: '*.get' matches 'user.get', 'post.get', etc.\n * - Full wildcard: '*' matches everything\n *\n * @param path - The procedure path to check\n * @param pattern - The pattern to match against\n * @returns Whether the path matches the pattern\n *\n * @example\n * matchPath('user.get', 'user.get') // true\n * matchPath('user.get', 'user.*') // true\n * matchPath('user.get', '*.get') // true\n * matchPath('user.get', '*') // true\n * matchPath('user.get', 'post.*') // false\n */\nexport function matchPath(path: string, pattern: string): boolean {\n if (pattern === '*') {\n return true\n }\n\n if (pattern === path) {\n return true\n }\n\n // Handle wildcard patterns\n if (pattern.includes('*')) {\n const regex = new RegExp(\n '^' +\n pattern\n .split('*')\n .map((s) => escapeRegex(s))\n .join('.*') +\n '$'\n )\n return regex.test(path)\n }\n\n return false\n}\n\n/**\n * Escape special regex characters in a string\n */\nfunction escapeRegex(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Filter fixtures based on include/exclude patterns\n *\n * @param fixtures - The fixture map to filter\n * @param include - Patterns to include (supports wildcards)\n * @param exclude - Patterns to exclude (takes precedence, supports wildcards)\n * @returns A new fixture map with only matching fixtures\n */\nexport function filterFixtures(\n fixtures: FlatFixtureMap,\n include?: string[],\n exclude?: string[]\n): FlatFixtureMap {\n const result: FlatFixtureMap = new Map()\n\n for (const [path, handler] of fixtures) {\n // Check if path should be included\n let shouldInclude = true\n\n if (include && include.length > 0) {\n shouldInclude = include.some((pattern) => matchPath(path, pattern))\n }\n\n // Check if path should be excluded\n if (exclude && exclude.length > 0) {\n if (exclude.some((pattern) => matchPath(path, pattern))) {\n shouldInclude = false\n }\n }\n\n if (shouldInclude) {\n result.set(path, handler)\n }\n }\n\n return result\n}\n\n/**\n * Get all procedure paths from a fixture map\n *\n * @param fixtures - The fixture map\n * @returns Array of all procedure paths\n */\nexport function getFixturePaths(fixtures: FlatFixtureMap): string[] {\n return Array.from(fixtures.keys())\n}\n\n/**\n * Merge multiple fixture maps\n *\n * Later maps take precedence over earlier ones for the same path.\n *\n * @param maps - Fixture maps to merge\n * @returns Merged fixture map\n */\nexport function mergeFixtures(...maps: FlatFixtureMap[]): FlatFixtureMap {\n const result: FlatFixtureMap = new Map()\n\n for (const map of maps) {\n for (const [path, handler] of map) {\n result.set(path, handler)\n }\n }\n\n return result\n}\n","import type { TRPCLink, Operation } from '@trpc/client'\nimport { observable } from '@trpc/server/observable'\nimport type { AnyRouter } from '@trpc/server'\nimport type {\n CreateDemoLinkOptions,\n TRPCFixtureContext,\n TRPCFixtureHandler,\n FlatFixtureMap,\n} from './types'\nimport { normalizeFixtures } from './fixtures'\nimport { findMatchingFixture, shouldIntercept } from './matcher'\n\n/**\n * Create a demo-aware tRPC link\n *\n * This link intercepts tRPC procedure calls when demo mode is enabled\n * and returns fixture data instead of making real API calls.\n *\n * The demo link should be placed before the terminating link (like httpBatchLink)\n * in your link chain.\n *\n * @example\n * import { createTRPCClient, httpBatchLink } from '@trpc/client'\n * import { createDemoLink } from '@demokit-ai/trpc'\n *\n * // Simple usage with fixtures\n * const client = createTRPCClient<AppRouter>({\n * links: [\n * createDemoLink({\n * fixtures: {\n * user: {\n * list: () => [{ id: '1', name: 'Demo User' }],\n * get: ({ input }) => ({ id: input.id, name: 'Demo User' }),\n * },\n * },\n * isEnabled: () => localStorage.getItem('demoMode') === 'true',\n * }),\n * httpBatchLink({ url: '/api/trpc' }),\n * ],\n * })\n *\n * @example\n * // With include/exclude filtering\n * createDemoLink({\n * fixtures: myFixtures,\n * include: ['user.*', 'post.list'], // Only intercept user.* and post.list\n * exclude: ['user.delete'], // Never intercept user.delete\n * delay: 200, // Simulate 200ms network latency\n * onMissing: (path, input) => {\n * console.warn(`No fixture for: ${path}`)\n * },\n * })\n */\nexport function createDemoLink<TRouter extends AnyRouter = AnyRouter>(\n options: CreateDemoLinkOptions<TRouter> = {}\n): TRPCLink<TRouter> {\n const {\n fixtures: rawFixtures,\n isEnabled = () => false,\n delay = 0,\n include,\n exclude,\n onMissing,\n } = options\n\n // Normalize fixtures to flat map on initialization\n const fixtures: FlatFixtureMap = normalizeFixtures(rawFixtures as Record<string, unknown>)\n\n // Return the link factory function\n return () => {\n // Return the link function that handles each operation\n return ({ next, op }) => {\n return observable((observer) => {\n // Check if demo mode is enabled\n if (!isEnabled()) {\n // Forward to next link\n const unsubscribe = next(op).subscribe({\n next(value) {\n observer.next(value)\n },\n error(err) {\n observer.error(err)\n },\n complete() {\n observer.complete()\n },\n })\n return unsubscribe\n }\n\n // Check if this procedure should be intercepted\n if (!shouldIntercept(op.path, include, exclude)) {\n // Forward to next link\n const unsubscribe = next(op).subscribe({\n next(value) {\n observer.next(value)\n },\n error(err) {\n observer.error(err)\n },\n complete() {\n observer.complete()\n },\n })\n return unsubscribe\n }\n\n // Find matching fixture\n const match = findMatchingFixture(fixtures, op.path)\n\n if (!match.matched || !match.handler) {\n // No fixture found\n onMissing?.(op.path, op.input)\n\n // Forward to next link as fallback\n const unsubscribe = next(op).subscribe({\n next(value) {\n observer.next(value)\n },\n error(err) {\n observer.error(err)\n },\n complete() {\n observer.complete()\n },\n })\n return unsubscribe\n }\n\n // Execute fixture handler\n const executeFixture = async () => {\n const context: TRPCFixtureContext = {\n path: op.path,\n input: op.input,\n type: op.type,\n }\n\n // Apply delay if configured\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay))\n }\n\n // Execute handler\n const handler = match.handler as TRPCFixtureHandler\n const result = typeof handler === 'function' ? await handler(context) : handler\n\n return result\n }\n\n // Handle async execution\n executeFixture()\n .then((data) => {\n observer.next({\n result: { data },\n })\n observer.complete()\n })\n .catch((err) => {\n observer.error(err)\n })\n\n // Return cleanup function (no-op for demo fixtures)\n return () => {}\n })\n }\n }\n}\n\n/**\n * Create a demo link with state management\n *\n * Returns the link along with controls to enable/disable demo mode\n * and manage fixtures at runtime.\n *\n * @example\n * const { link, enable, disable, isEnabled, setFixture, removeFixture } =\n * createDemoLinkWithState({\n * fixtures: myFixtures,\n * })\n *\n * const client = createTRPCClient<AppRouter>({\n * links: [link, httpBatchLink({ url: '/api/trpc' })],\n * })\n *\n * // Later...\n * enable() // Turn on demo mode\n * disable() // Turn off demo mode\n *\n * // Add fixture at runtime\n * setFixture('user.get', ({ input }) => ({ id: input.id, name: 'Runtime User' }))\n */\nexport function createDemoLinkWithState<TRouter extends AnyRouter = AnyRouter>(\n options: Omit<CreateDemoLinkOptions<TRouter>, 'isEnabled'> & {\n /**\n * Initial enabled state\n * @default false\n */\n enabled?: boolean\n } = {}\n) {\n const { fixtures: rawFixtures, enabled: initialEnabled = false, ...rest } = options\n\n let enabled = initialEnabled\n const fixtures: FlatFixtureMap = normalizeFixtures(rawFixtures as Record<string, unknown>)\n\n const link = createDemoLink<TRouter>({\n ...rest,\n fixtures,\n isEnabled: () => enabled,\n })\n\n return {\n /**\n * The tRPC link to use in your client\n */\n link,\n\n /**\n * Enable demo mode\n */\n enable: () => {\n enabled = true\n },\n\n /**\n * Disable demo mode\n */\n disable: () => {\n enabled = false\n },\n\n /**\n * Check if demo mode is enabled\n */\n isEnabled: () => enabled,\n\n /**\n * Toggle demo mode\n */\n toggle: () => {\n enabled = !enabled\n return enabled\n },\n\n /**\n * Set or update a fixture\n */\n setFixture: (path: string, handler: TRPCFixtureHandler) => {\n fixtures.set(path, handler)\n },\n\n /**\n * Remove a fixture\n */\n removeFixture: (path: string) => {\n fixtures.delete(path)\n },\n\n /**\n * Get all fixtures\n */\n getFixtures: () => fixtures,\n\n /**\n * Clear all fixtures\n */\n clearFixtures: () => {\n fixtures.clear()\n },\n }\n}\n\nexport type DemoLinkWithState<TRouter extends AnyRouter = AnyRouter> = ReturnType<\n typeof createDemoLinkWithState<TRouter>\n>\n"],"mappings":";AAuCO,SAAS,qBAAgD;AAkB9D,SAAO,SAA2D,UAAgB;AAChF,WAAO;AAAA,EACT;AACF;AAaO,SAAS,iBACd,UACgB;AAChB,SAAO,IAAI,IAAI,OAAO,QAAQ,QAAQ,CAAC;AACzC;AAmEO,SAAS,qBACd,SACqC;AACrC,SAAO;AACT;AAOO,SAAS,kBACd,UACgB;AAChB,MAAI,CAAC,UAAU;AACb,WAAO,oBA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,SAAiB;AAC/B,eAAS,OAAO,IAAI;AAAA,IACtB;AAAA;AAAA;AAAA;AAAA,IAKA,aAAa,MAAM;AAAA;AAAA;AAAA;AAAA,IAKnB,eAAe,MAAM;AACnB,eAAS,MAAM;AAAA,IACjB;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
createDemoLink: () => createDemoLink,
|
|
24
|
+
createDemoLinkWithState: () => createDemoLinkWithState,
|
|
25
|
+
createFixtureHandler: () => createFixtureHandler,
|
|
26
|
+
defineFixtureMap: () => defineFixtureMap,
|
|
27
|
+
defineTRPCFixtures: () => defineTRPCFixtures,
|
|
28
|
+
filterFixtures: () => filterFixtures,
|
|
29
|
+
findMatchingFixture: () => findMatchingFixture,
|
|
30
|
+
getFixturePaths: () => getFixturePaths,
|
|
31
|
+
matchPath: () => matchPath,
|
|
32
|
+
mergeFixtures: () => mergeFixtures,
|
|
33
|
+
normalizeFixtures: () => normalizeFixtures,
|
|
34
|
+
shouldIntercept: () => shouldIntercept
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
4
37
|
|
|
5
38
|
// src/link.ts
|
|
39
|
+
var import_observable = require("@trpc/server/observable");
|
|
6
40
|
|
|
7
41
|
// src/fixtures.ts
|
|
8
42
|
function defineTRPCFixtures() {
|
|
@@ -131,7 +165,7 @@ function createDemoLink(options = {}) {
|
|
|
131
165
|
const fixtures = normalizeFixtures(rawFixtures);
|
|
132
166
|
return () => {
|
|
133
167
|
return ({ next, op }) => {
|
|
134
|
-
return
|
|
168
|
+
return (0, import_observable.observable)((observer) => {
|
|
135
169
|
if (!isEnabled()) {
|
|
136
170
|
const unsubscribe = next(op).subscribe({
|
|
137
171
|
next(value) {
|
|
@@ -264,18 +298,19 @@ function createDemoLinkWithState(options = {}) {
|
|
|
264
298
|
}
|
|
265
299
|
};
|
|
266
300
|
}
|
|
267
|
-
|
|
268
|
-
exports
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
301
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
302
|
+
0 && (module.exports = {
|
|
303
|
+
createDemoLink,
|
|
304
|
+
createDemoLinkWithState,
|
|
305
|
+
createFixtureHandler,
|
|
306
|
+
defineFixtureMap,
|
|
307
|
+
defineTRPCFixtures,
|
|
308
|
+
filterFixtures,
|
|
309
|
+
findMatchingFixture,
|
|
310
|
+
getFixturePaths,
|
|
311
|
+
matchPath,
|
|
312
|
+
mergeFixtures,
|
|
313
|
+
normalizeFixtures,
|
|
314
|
+
shouldIntercept
|
|
315
|
+
});
|
|
281
316
|
//# sourceMappingURL=index.cjs.map
|