@demokit-ai/trpc 0.0.1

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/index.cjs ADDED
@@ -0,0 +1,281 @@
1
+ 'use strict';
2
+
3
+ var observable = require('@trpc/server/observable');
4
+
5
+ // src/link.ts
6
+
7
+ // src/fixtures.ts
8
+ function defineTRPCFixtures() {
9
+ return function(fixtures) {
10
+ return fixtures;
11
+ };
12
+ }
13
+ function defineFixtureMap(fixtures) {
14
+ return new Map(Object.entries(fixtures));
15
+ }
16
+ function createFixtureHandler(handler) {
17
+ return handler;
18
+ }
19
+ function normalizeFixtures(fixtures) {
20
+ if (!fixtures) {
21
+ return /* @__PURE__ */ new Map();
22
+ }
23
+ if (fixtures instanceof Map) {
24
+ return fixtures;
25
+ }
26
+ const result = /* @__PURE__ */ new Map();
27
+ function flatten(obj, prefix = "") {
28
+ for (const [key, value] of Object.entries(obj)) {
29
+ const path = prefix ? `${prefix}.${key}` : key;
30
+ if (value !== null && typeof value === "object" && !Array.isArray(value) && typeof value !== "function") {
31
+ const hasNestedProcedures = Object.values(value).some(
32
+ (v) => typeof v === "function" || Array.isArray(v) || typeof v === "object" && v !== null
33
+ );
34
+ if (hasNestedProcedures) {
35
+ flatten(value, path);
36
+ } else {
37
+ result.set(path, value);
38
+ }
39
+ } else {
40
+ result.set(path, value);
41
+ }
42
+ }
43
+ }
44
+ flatten(fixtures);
45
+ return result;
46
+ }
47
+
48
+ // src/matcher.ts
49
+ function findMatchingFixture(fixtures, path) {
50
+ const handler = fixtures.get(path);
51
+ if (handler !== void 0) {
52
+ return {
53
+ matched: true,
54
+ handler,
55
+ path
56
+ };
57
+ }
58
+ return {
59
+ matched: false,
60
+ path
61
+ };
62
+ }
63
+ function shouldIntercept(path, include, exclude) {
64
+ if (exclude?.includes(path)) {
65
+ return false;
66
+ }
67
+ if (include && include.length > 0) {
68
+ return include.includes(path);
69
+ }
70
+ return true;
71
+ }
72
+ function matchPath(path, pattern) {
73
+ if (pattern === "*") {
74
+ return true;
75
+ }
76
+ if (pattern === path) {
77
+ return true;
78
+ }
79
+ if (pattern.includes("*")) {
80
+ const regex = new RegExp(
81
+ "^" + pattern.split("*").map((s) => escapeRegex(s)).join(".*") + "$"
82
+ );
83
+ return regex.test(path);
84
+ }
85
+ return false;
86
+ }
87
+ function escapeRegex(str) {
88
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
89
+ }
90
+ function filterFixtures(fixtures, include, exclude) {
91
+ const result = /* @__PURE__ */ new Map();
92
+ for (const [path, handler] of fixtures) {
93
+ let shouldInclude = true;
94
+ if (include && include.length > 0) {
95
+ shouldInclude = include.some((pattern) => matchPath(path, pattern));
96
+ }
97
+ if (exclude && exclude.length > 0) {
98
+ if (exclude.some((pattern) => matchPath(path, pattern))) {
99
+ shouldInclude = false;
100
+ }
101
+ }
102
+ if (shouldInclude) {
103
+ result.set(path, handler);
104
+ }
105
+ }
106
+ return result;
107
+ }
108
+ function getFixturePaths(fixtures) {
109
+ return Array.from(fixtures.keys());
110
+ }
111
+ function mergeFixtures(...maps) {
112
+ const result = /* @__PURE__ */ new Map();
113
+ for (const map of maps) {
114
+ for (const [path, handler] of map) {
115
+ result.set(path, handler);
116
+ }
117
+ }
118
+ return result;
119
+ }
120
+
121
+ // src/link.ts
122
+ function createDemoLink(options = {}) {
123
+ const {
124
+ fixtures: rawFixtures,
125
+ isEnabled = () => false,
126
+ delay = 0,
127
+ include,
128
+ exclude,
129
+ onMissing
130
+ } = options;
131
+ const fixtures = normalizeFixtures(rawFixtures);
132
+ return () => {
133
+ return ({ next, op }) => {
134
+ return observable.observable((observer) => {
135
+ if (!isEnabled()) {
136
+ const unsubscribe = next(op).subscribe({
137
+ next(value) {
138
+ observer.next(value);
139
+ },
140
+ error(err) {
141
+ observer.error(err);
142
+ },
143
+ complete() {
144
+ observer.complete();
145
+ }
146
+ });
147
+ return unsubscribe;
148
+ }
149
+ if (!shouldIntercept(op.path, include, exclude)) {
150
+ const unsubscribe = next(op).subscribe({
151
+ next(value) {
152
+ observer.next(value);
153
+ },
154
+ error(err) {
155
+ observer.error(err);
156
+ },
157
+ complete() {
158
+ observer.complete();
159
+ }
160
+ });
161
+ return unsubscribe;
162
+ }
163
+ const match = findMatchingFixture(fixtures, op.path);
164
+ if (!match.matched || !match.handler) {
165
+ onMissing?.(op.path, op.input);
166
+ const unsubscribe = next(op).subscribe({
167
+ next(value) {
168
+ observer.next(value);
169
+ },
170
+ error(err) {
171
+ observer.error(err);
172
+ },
173
+ complete() {
174
+ observer.complete();
175
+ }
176
+ });
177
+ return unsubscribe;
178
+ }
179
+ const executeFixture = async () => {
180
+ const context = {
181
+ path: op.path,
182
+ input: op.input,
183
+ type: op.type
184
+ };
185
+ if (delay > 0) {
186
+ await new Promise((resolve) => setTimeout(resolve, delay));
187
+ }
188
+ const handler = match.handler;
189
+ const result = typeof handler === "function" ? await handler(context) : handler;
190
+ return result;
191
+ };
192
+ executeFixture().then((data) => {
193
+ observer.next({
194
+ result: { data }
195
+ });
196
+ observer.complete();
197
+ }).catch((err) => {
198
+ observer.error(err);
199
+ });
200
+ return () => {
201
+ };
202
+ });
203
+ };
204
+ };
205
+ }
206
+ function createDemoLinkWithState(options = {}) {
207
+ const { fixtures: rawFixtures, enabled: initialEnabled = false, ...rest } = options;
208
+ let enabled = initialEnabled;
209
+ const fixtures = normalizeFixtures(rawFixtures);
210
+ const link = createDemoLink({
211
+ ...rest,
212
+ fixtures,
213
+ isEnabled: () => enabled
214
+ });
215
+ return {
216
+ /**
217
+ * The tRPC link to use in your client
218
+ */
219
+ link,
220
+ /**
221
+ * Enable demo mode
222
+ */
223
+ enable: () => {
224
+ enabled = true;
225
+ },
226
+ /**
227
+ * Disable demo mode
228
+ */
229
+ disable: () => {
230
+ enabled = false;
231
+ },
232
+ /**
233
+ * Check if demo mode is enabled
234
+ */
235
+ isEnabled: () => enabled,
236
+ /**
237
+ * Toggle demo mode
238
+ */
239
+ toggle: () => {
240
+ enabled = !enabled;
241
+ return enabled;
242
+ },
243
+ /**
244
+ * Set or update a fixture
245
+ */
246
+ setFixture: (path, handler) => {
247
+ fixtures.set(path, handler);
248
+ },
249
+ /**
250
+ * Remove a fixture
251
+ */
252
+ removeFixture: (path) => {
253
+ fixtures.delete(path);
254
+ },
255
+ /**
256
+ * Get all fixtures
257
+ */
258
+ getFixtures: () => fixtures,
259
+ /**
260
+ * Clear all fixtures
261
+ */
262
+ clearFixtures: () => {
263
+ fixtures.clear();
264
+ }
265
+ };
266
+ }
267
+
268
+ exports.createDemoLink = createDemoLink;
269
+ exports.createDemoLinkWithState = createDemoLinkWithState;
270
+ exports.createFixtureHandler = createFixtureHandler;
271
+ exports.defineFixtureMap = defineFixtureMap;
272
+ exports.defineTRPCFixtures = defineTRPCFixtures;
273
+ exports.filterFixtures = filterFixtures;
274
+ exports.findMatchingFixture = findMatchingFixture;
275
+ exports.getFixturePaths = getFixturePaths;
276
+ exports.matchPath = matchPath;
277
+ exports.mergeFixtures = mergeFixtures;
278
+ exports.normalizeFixtures = normalizeFixtures;
279
+ exports.shouldIntercept = shouldIntercept;
280
+ //# sourceMappingURL=index.cjs.map
281
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/fixtures.ts","../src/matcher.ts","../src/link.ts"],"names":["observable"],"mappings":";;;;;;;AAuCO,SAAS,kBAAA,GAAgD;AAkB9D,EAAA,OAAO,SAA2D,QAAA,EAAgB;AAChF,IAAA,OAAO,QAAA;AAAA,EACT,CAAA;AACF;AAaO,SAAS,iBACd,QAAA,EACgB;AAChB,EAAA,OAAO,IAAI,GAAA,CAAI,MAAA,CAAO,OAAA,CAAQ,QAAQ,CAAC,CAAA;AACzC;AAmEO,SAAS,qBACd,OAAA,EACqC;AACrC,EAAA,OAAO,OAAA;AACT;AAOO,SAAS,kBACd,QAAA,EACgB;AAChB,EAAA,IAAI,CAAC,QAAA,EAAU;AACb,IAAA,2BAAW,GAA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A,IACtB,CAAA;AAAA;AAAA;AAAA;AAAA,IAKA,aAAa,MAAM,QAAA;AAAA;AAAA;AAAA;AAAA,IAKnB,eAAe,MAAM;AACnB,MAAA,QAAA,CAAS,KAAA,EAAM;AAAA,IACjB;AAAA,GACF;AACF","file":"index.cjs","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"]}
@@ -0,0 +1,96 @@
1
+ import { F as FlatFixtureMap, a as FixtureMatchResult } from './fixtures-BV-EUS_X.cjs';
2
+ export { C as CreateDemoLinkOptions, D as DemoLinkWithState, j as DemoTRPCProviderConfig, k as DemoTRPCProviderProps, l as DemoTRPCState, i as FlatFixtureMapObject, N as NestedFixtures, R as RouterInputs, h as RouterOutputs, T as TRPCFixtureContext, g as TRPCFixtureHandler, c as createDemoLink, b as createDemoLinkWithState, f as createFixtureHandler, e as defineFixtureMap, d as defineTRPCFixtures, n as normalizeFixtures } from './fixtures-BV-EUS_X.cjs';
3
+ import '@trpc/client';
4
+ import '@trpc/server';
5
+ import '@trpc/server/unstable-core-do-not-import';
6
+ import 'react';
7
+
8
+ /**
9
+ * Find a matching fixture for a procedure path
10
+ *
11
+ * @param fixtures - Map of procedure paths to fixture handlers
12
+ * @param path - The procedure path to match (e.g., 'user.get', 'post.list')
13
+ * @returns Match result with handler if found
14
+ *
15
+ * @example
16
+ * const fixtures = new Map([
17
+ * ['user.list', () => []],
18
+ * ['user.get', ({ input }) => ({ id: input.id })],
19
+ * ])
20
+ *
21
+ * findMatchingFixture(fixtures, 'user.get')
22
+ * // { matched: true, handler: Function, path: 'user.get' }
23
+ *
24
+ * findMatchingFixture(fixtures, 'unknown.path')
25
+ * // { matched: false, path: 'unknown.path' }
26
+ */
27
+ declare function findMatchingFixture<TOutput = unknown>(fixtures: FlatFixtureMap, path: string): FixtureMatchResult<TOutput>;
28
+ /**
29
+ * Check if a procedure path should be intercepted based on include/exclude rules
30
+ *
31
+ * @param path - The procedure path to check
32
+ * @param include - Optional list of paths to include (if provided, only these are intercepted)
33
+ * @param exclude - Optional list of paths to exclude (takes precedence over include)
34
+ * @returns Whether the path should be intercepted
35
+ *
36
+ * @example
37
+ * // Include only specific paths
38
+ * shouldIntercept('user.get', ['user.get', 'user.list'], [])
39
+ * // true
40
+ *
41
+ * shouldIntercept('post.list', ['user.get', 'user.list'], [])
42
+ * // false
43
+ *
44
+ * // Exclude takes precedence
45
+ * shouldIntercept('user.get', ['user.get'], ['user.get'])
46
+ * // false
47
+ */
48
+ declare function shouldIntercept(path: string, include?: string[], exclude?: string[]): boolean;
49
+ /**
50
+ * Check if a procedure path matches a pattern with wildcards
51
+ *
52
+ * Supports:
53
+ * - Exact match: 'user.get' matches 'user.get'
54
+ * - Wildcard suffix: 'user.*' matches 'user.get', 'user.list', etc.
55
+ * - Wildcard prefix: '*.get' matches 'user.get', 'post.get', etc.
56
+ * - Full wildcard: '*' matches everything
57
+ *
58
+ * @param path - The procedure path to check
59
+ * @param pattern - The pattern to match against
60
+ * @returns Whether the path matches the pattern
61
+ *
62
+ * @example
63
+ * matchPath('user.get', 'user.get') // true
64
+ * matchPath('user.get', 'user.*') // true
65
+ * matchPath('user.get', '*.get') // true
66
+ * matchPath('user.get', '*') // true
67
+ * matchPath('user.get', 'post.*') // false
68
+ */
69
+ declare function matchPath(path: string, pattern: string): boolean;
70
+ /**
71
+ * Filter fixtures based on include/exclude patterns
72
+ *
73
+ * @param fixtures - The fixture map to filter
74
+ * @param include - Patterns to include (supports wildcards)
75
+ * @param exclude - Patterns to exclude (takes precedence, supports wildcards)
76
+ * @returns A new fixture map with only matching fixtures
77
+ */
78
+ declare function filterFixtures(fixtures: FlatFixtureMap, include?: string[], exclude?: string[]): FlatFixtureMap;
79
+ /**
80
+ * Get all procedure paths from a fixture map
81
+ *
82
+ * @param fixtures - The fixture map
83
+ * @returns Array of all procedure paths
84
+ */
85
+ declare function getFixturePaths(fixtures: FlatFixtureMap): string[];
86
+ /**
87
+ * Merge multiple fixture maps
88
+ *
89
+ * Later maps take precedence over earlier ones for the same path.
90
+ *
91
+ * @param maps - Fixture maps to merge
92
+ * @returns Merged fixture map
93
+ */
94
+ declare function mergeFixtures(...maps: FlatFixtureMap[]): FlatFixtureMap;
95
+
96
+ export { FixtureMatchResult, FlatFixtureMap, filterFixtures, findMatchingFixture, getFixturePaths, matchPath, mergeFixtures, shouldIntercept };
@@ -0,0 +1,96 @@
1
+ import { F as FlatFixtureMap, a as FixtureMatchResult } from './fixtures-BV-EUS_X.js';
2
+ export { C as CreateDemoLinkOptions, D as DemoLinkWithState, j as DemoTRPCProviderConfig, k as DemoTRPCProviderProps, l as DemoTRPCState, i as FlatFixtureMapObject, N as NestedFixtures, R as RouterInputs, h as RouterOutputs, T as TRPCFixtureContext, g as TRPCFixtureHandler, c as createDemoLink, b as createDemoLinkWithState, f as createFixtureHandler, e as defineFixtureMap, d as defineTRPCFixtures, n as normalizeFixtures } from './fixtures-BV-EUS_X.js';
3
+ import '@trpc/client';
4
+ import '@trpc/server';
5
+ import '@trpc/server/unstable-core-do-not-import';
6
+ import 'react';
7
+
8
+ /**
9
+ * Find a matching fixture for a procedure path
10
+ *
11
+ * @param fixtures - Map of procedure paths to fixture handlers
12
+ * @param path - The procedure path to match (e.g., 'user.get', 'post.list')
13
+ * @returns Match result with handler if found
14
+ *
15
+ * @example
16
+ * const fixtures = new Map([
17
+ * ['user.list', () => []],
18
+ * ['user.get', ({ input }) => ({ id: input.id })],
19
+ * ])
20
+ *
21
+ * findMatchingFixture(fixtures, 'user.get')
22
+ * // { matched: true, handler: Function, path: 'user.get' }
23
+ *
24
+ * findMatchingFixture(fixtures, 'unknown.path')
25
+ * // { matched: false, path: 'unknown.path' }
26
+ */
27
+ declare function findMatchingFixture<TOutput = unknown>(fixtures: FlatFixtureMap, path: string): FixtureMatchResult<TOutput>;
28
+ /**
29
+ * Check if a procedure path should be intercepted based on include/exclude rules
30
+ *
31
+ * @param path - The procedure path to check
32
+ * @param include - Optional list of paths to include (if provided, only these are intercepted)
33
+ * @param exclude - Optional list of paths to exclude (takes precedence over include)
34
+ * @returns Whether the path should be intercepted
35
+ *
36
+ * @example
37
+ * // Include only specific paths
38
+ * shouldIntercept('user.get', ['user.get', 'user.list'], [])
39
+ * // true
40
+ *
41
+ * shouldIntercept('post.list', ['user.get', 'user.list'], [])
42
+ * // false
43
+ *
44
+ * // Exclude takes precedence
45
+ * shouldIntercept('user.get', ['user.get'], ['user.get'])
46
+ * // false
47
+ */
48
+ declare function shouldIntercept(path: string, include?: string[], exclude?: string[]): boolean;
49
+ /**
50
+ * Check if a procedure path matches a pattern with wildcards
51
+ *
52
+ * Supports:
53
+ * - Exact match: 'user.get' matches 'user.get'
54
+ * - Wildcard suffix: 'user.*' matches 'user.get', 'user.list', etc.
55
+ * - Wildcard prefix: '*.get' matches 'user.get', 'post.get', etc.
56
+ * - Full wildcard: '*' matches everything
57
+ *
58
+ * @param path - The procedure path to check
59
+ * @param pattern - The pattern to match against
60
+ * @returns Whether the path matches the pattern
61
+ *
62
+ * @example
63
+ * matchPath('user.get', 'user.get') // true
64
+ * matchPath('user.get', 'user.*') // true
65
+ * matchPath('user.get', '*.get') // true
66
+ * matchPath('user.get', '*') // true
67
+ * matchPath('user.get', 'post.*') // false
68
+ */
69
+ declare function matchPath(path: string, pattern: string): boolean;
70
+ /**
71
+ * Filter fixtures based on include/exclude patterns
72
+ *
73
+ * @param fixtures - The fixture map to filter
74
+ * @param include - Patterns to include (supports wildcards)
75
+ * @param exclude - Patterns to exclude (takes precedence, supports wildcards)
76
+ * @returns A new fixture map with only matching fixtures
77
+ */
78
+ declare function filterFixtures(fixtures: FlatFixtureMap, include?: string[], exclude?: string[]): FlatFixtureMap;
79
+ /**
80
+ * Get all procedure paths from a fixture map
81
+ *
82
+ * @param fixtures - The fixture map
83
+ * @returns Array of all procedure paths
84
+ */
85
+ declare function getFixturePaths(fixtures: FlatFixtureMap): string[];
86
+ /**
87
+ * Merge multiple fixture maps
88
+ *
89
+ * Later maps take precedence over earlier ones for the same path.
90
+ *
91
+ * @param maps - Fixture maps to merge
92
+ * @returns Merged fixture map
93
+ */
94
+ declare function mergeFixtures(...maps: FlatFixtureMap[]): FlatFixtureMap;
95
+
96
+ export { FixtureMatchResult, FlatFixtureMap, filterFixtures, findMatchingFixture, getFixturePaths, matchPath, mergeFixtures, shouldIntercept };