@demokit-ai/remix 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/fixtures-BP3SzTkj.d.cts +355 -0
- package/dist/fixtures-BP3SzTkj.d.ts +355 -0
- package/dist/index.cjs +385 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +195 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.js +346 -0
- package/dist/index.js.map +1 -0
- package/dist/server.cjs +307 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +162 -0
- package/dist/server.d.ts +162 -0
- package/dist/server.js +268 -0
- package/dist/server.js.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { MatchResult } from '@demokit-ai/core';
|
|
2
|
+
import { LoaderFunctionArgs, ActionFunctionArgs, TypedResponse } from '@remix-run/node';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context passed to loader fixture handlers
|
|
6
|
+
*/
|
|
7
|
+
interface LoaderFixtureContext {
|
|
8
|
+
/** Route params extracted from the URL */
|
|
9
|
+
params: Record<string, string | undefined>;
|
|
10
|
+
/** The original request object */
|
|
11
|
+
request: Request;
|
|
12
|
+
/** Matched route path pattern */
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Context passed to action fixture handlers
|
|
17
|
+
*/
|
|
18
|
+
interface ActionFixtureContext {
|
|
19
|
+
/** Route params extracted from the URL */
|
|
20
|
+
params: Record<string, string | undefined>;
|
|
21
|
+
/** The original request object */
|
|
22
|
+
request: Request;
|
|
23
|
+
/** Matched route path pattern */
|
|
24
|
+
path: string;
|
|
25
|
+
/** Parsed form data (convenience method result) */
|
|
26
|
+
formData?: FormData;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Loader fixture handler function or static value
|
|
30
|
+
*/
|
|
31
|
+
type LoaderFixtureHandler<T = unknown> = T | ((context: LoaderFixtureContext) => T | Promise<T>);
|
|
32
|
+
/**
|
|
33
|
+
* Action fixture handler function or static value
|
|
34
|
+
*/
|
|
35
|
+
type ActionFixtureHandler<T = unknown> = T | ((context: ActionFixtureContext) => T | Promise<T>);
|
|
36
|
+
/**
|
|
37
|
+
* Map of route paths to loader fixtures
|
|
38
|
+
*
|
|
39
|
+
* Keys are route path patterns like '/users/:id' or '/projects'
|
|
40
|
+
*/
|
|
41
|
+
type LoaderFixtureMap = Map<string, LoaderFixtureHandler>;
|
|
42
|
+
/**
|
|
43
|
+
* Object-based loader fixture map for easier definition
|
|
44
|
+
*/
|
|
45
|
+
type LoaderFixtureMapObject = Record<string, LoaderFixtureHandler>;
|
|
46
|
+
/**
|
|
47
|
+
* Map of route paths to action fixtures
|
|
48
|
+
*
|
|
49
|
+
* Keys are route path patterns like '/users/:id' or '/projects'
|
|
50
|
+
* Values can be keyed by HTTP method: { POST: handler, PUT: handler }
|
|
51
|
+
*/
|
|
52
|
+
type ActionFixtureMap = Map<string, ActionFixtureHandler | MethodActionHandlers>;
|
|
53
|
+
/**
|
|
54
|
+
* Object-based action fixture map for easier definition
|
|
55
|
+
*/
|
|
56
|
+
type ActionFixtureMapObject = Record<string, ActionFixtureHandler | MethodActionHandlers>;
|
|
57
|
+
/**
|
|
58
|
+
* Action handlers organized by HTTP method
|
|
59
|
+
*/
|
|
60
|
+
interface MethodActionHandlers {
|
|
61
|
+
POST?: ActionFixtureHandler;
|
|
62
|
+
PUT?: ActionFixtureHandler;
|
|
63
|
+
PATCH?: ActionFixtureHandler;
|
|
64
|
+
DELETE?: ActionFixtureHandler;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for creating a demo-aware loader
|
|
68
|
+
*/
|
|
69
|
+
interface CreateDemoLoaderOptions<T = unknown> {
|
|
70
|
+
/**
|
|
71
|
+
* The real loader function to use when demo mode is disabled
|
|
72
|
+
*/
|
|
73
|
+
loader: (args: LoaderFunctionArgs) => T | Promise<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Function to check if demo mode is enabled
|
|
76
|
+
* Can check cookies, headers, or environment variables
|
|
77
|
+
* @default () => false
|
|
78
|
+
*/
|
|
79
|
+
isEnabled?: (request: Request) => boolean | Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Demo fixture to return when demo mode is enabled
|
|
82
|
+
* Can be a static value or a function
|
|
83
|
+
*/
|
|
84
|
+
fixture?: LoaderFixtureHandler<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Simulated delay in milliseconds
|
|
87
|
+
* @default 0
|
|
88
|
+
*/
|
|
89
|
+
delay?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Callback when demo mode is used
|
|
92
|
+
*/
|
|
93
|
+
onDemo?: (context: LoaderFixtureContext) => void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options for creating a demo-aware action
|
|
97
|
+
*/
|
|
98
|
+
interface CreateDemoActionOptions<T = unknown> {
|
|
99
|
+
/**
|
|
100
|
+
* The real action function to use when demo mode is disabled
|
|
101
|
+
*/
|
|
102
|
+
action: (args: ActionFunctionArgs) => T | Promise<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Function to check if demo mode is enabled
|
|
105
|
+
* Can check cookies, headers, or environment variables
|
|
106
|
+
* @default () => false
|
|
107
|
+
*/
|
|
108
|
+
isEnabled?: (request: Request) => boolean | Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Demo fixture to return when demo mode is enabled
|
|
111
|
+
* Can be a static value, a function, or organized by HTTP method
|
|
112
|
+
*/
|
|
113
|
+
fixture?: ActionFixtureHandler<T> | MethodActionHandlers;
|
|
114
|
+
/**
|
|
115
|
+
* Simulated delay in milliseconds
|
|
116
|
+
* @default 0
|
|
117
|
+
*/
|
|
118
|
+
delay?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Callback when demo mode is used
|
|
121
|
+
*/
|
|
122
|
+
onDemo?: (context: ActionFixtureContext) => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Options for the demo route wrapper
|
|
126
|
+
*/
|
|
127
|
+
interface DemoRouteOptions {
|
|
128
|
+
/**
|
|
129
|
+
* Function to check if demo mode is enabled
|
|
130
|
+
*/
|
|
131
|
+
isEnabled?: (request: Request) => boolean | Promise<boolean>;
|
|
132
|
+
/**
|
|
133
|
+
* Default delay for all fixtures
|
|
134
|
+
*/
|
|
135
|
+
delay?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Loader fixtures by path
|
|
138
|
+
*/
|
|
139
|
+
loaders?: LoaderFixtureMapObject;
|
|
140
|
+
/**
|
|
141
|
+
* Action fixtures by path
|
|
142
|
+
*/
|
|
143
|
+
actions?: ActionFixtureMapObject;
|
|
144
|
+
/**
|
|
145
|
+
* Callback when no fixture is found
|
|
146
|
+
*/
|
|
147
|
+
onMissing?: (type: 'loader' | 'action', path: string) => void;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* State for the demo remix context
|
|
151
|
+
*/
|
|
152
|
+
interface DemoRemixState {
|
|
153
|
+
/** Whether demo mode is enabled */
|
|
154
|
+
enabled: boolean;
|
|
155
|
+
/** Current loader fixtures */
|
|
156
|
+
loaders: LoaderFixtureMap;
|
|
157
|
+
/** Current action fixtures */
|
|
158
|
+
actions: ActionFixtureMap;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provider configuration
|
|
162
|
+
*/
|
|
163
|
+
interface DemoRemixProviderConfig {
|
|
164
|
+
/**
|
|
165
|
+
* Whether demo mode is enabled
|
|
166
|
+
* @default false
|
|
167
|
+
*/
|
|
168
|
+
enabled?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Loader fixtures
|
|
171
|
+
*/
|
|
172
|
+
loaders?: LoaderFixtureMapObject;
|
|
173
|
+
/**
|
|
174
|
+
* Action fixtures
|
|
175
|
+
*/
|
|
176
|
+
actions?: ActionFixtureMapObject;
|
|
177
|
+
/**
|
|
178
|
+
* Simulated delay in milliseconds
|
|
179
|
+
* @default 0
|
|
180
|
+
*/
|
|
181
|
+
delay?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Props for DemoRemixProvider
|
|
185
|
+
*/
|
|
186
|
+
interface DemoRemixProviderProps extends DemoRemixProviderConfig {
|
|
187
|
+
children: React.ReactNode;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Demo mode detection options
|
|
191
|
+
*/
|
|
192
|
+
interface DemoModeOptions {
|
|
193
|
+
/**
|
|
194
|
+
* Cookie name to check for demo mode
|
|
195
|
+
* @default 'demokit-demo-mode'
|
|
196
|
+
*/
|
|
197
|
+
cookieName?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Header name to check for demo mode
|
|
200
|
+
* @default 'x-demokit-demo-mode'
|
|
201
|
+
*/
|
|
202
|
+
headerName?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Environment variable to check for demo mode
|
|
205
|
+
* @default 'DEMOKIT_DEMO_MODE'
|
|
206
|
+
*/
|
|
207
|
+
envVar?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Query parameter to check for demo mode
|
|
210
|
+
* @default 'demo'
|
|
211
|
+
*/
|
|
212
|
+
queryParam?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Server-side fixture store configuration
|
|
216
|
+
*/
|
|
217
|
+
interface FixtureStoreConfig {
|
|
218
|
+
/**
|
|
219
|
+
* Loader fixtures by route path
|
|
220
|
+
*/
|
|
221
|
+
loaders?: LoaderFixtureMapObject;
|
|
222
|
+
/**
|
|
223
|
+
* Action fixtures by route path
|
|
224
|
+
*/
|
|
225
|
+
actions?: ActionFixtureMapObject;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Result type from Remix loaders/actions (supports json, defer, redirect)
|
|
229
|
+
*/
|
|
230
|
+
type RemixResponse<T> = T | TypedResponse<T>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Server-side fixture store for managing demo data
|
|
234
|
+
*
|
|
235
|
+
* Use this to centralize fixture definitions for your Remix app.
|
|
236
|
+
* Works with the demo mode detection utilities.
|
|
237
|
+
*/
|
|
238
|
+
declare class FixtureStore {
|
|
239
|
+
private loaders;
|
|
240
|
+
private actions;
|
|
241
|
+
constructor(config?: FixtureStoreConfig);
|
|
242
|
+
/**
|
|
243
|
+
* Register a loader fixture
|
|
244
|
+
*/
|
|
245
|
+
setLoader(path: string, handler: LoaderFixtureHandler): this;
|
|
246
|
+
/**
|
|
247
|
+
* Register an action fixture
|
|
248
|
+
*/
|
|
249
|
+
setAction(path: string, handler: ActionFixtureHandler | MethodActionHandlers): this;
|
|
250
|
+
/**
|
|
251
|
+
* Get a loader fixture for a path
|
|
252
|
+
*/
|
|
253
|
+
getLoader(path: string): LoaderFixtureHandler | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Get an action fixture for a path and method
|
|
256
|
+
*/
|
|
257
|
+
getAction(path: string, method: string): ActionFixtureHandler | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Find loader fixture with match info
|
|
260
|
+
*/
|
|
261
|
+
findLoader(path: string): {
|
|
262
|
+
handler: LoaderFixtureHandler;
|
|
263
|
+
match: MatchResult;
|
|
264
|
+
} | null;
|
|
265
|
+
/**
|
|
266
|
+
* Find action fixture with match info
|
|
267
|
+
*/
|
|
268
|
+
findAction(path: string, method: string): {
|
|
269
|
+
handler: ActionFixtureHandler;
|
|
270
|
+
match: MatchResult;
|
|
271
|
+
} | null;
|
|
272
|
+
/**
|
|
273
|
+
* Get all loader fixtures
|
|
274
|
+
*/
|
|
275
|
+
getLoaders(): LoaderFixtureMapObject;
|
|
276
|
+
/**
|
|
277
|
+
* Get all action fixtures
|
|
278
|
+
*/
|
|
279
|
+
getActions(): ActionFixtureMapObject;
|
|
280
|
+
/**
|
|
281
|
+
* Clear all fixtures
|
|
282
|
+
*/
|
|
283
|
+
clear(): void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Create a fixture store with initial fixtures
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* import { createFixtureStore } from '@demokit-ai/remix/server'
|
|
290
|
+
*
|
|
291
|
+
* export const fixtures = createFixtureStore({
|
|
292
|
+
* loaders: {
|
|
293
|
+
* '/users': [{ id: '1', name: 'Demo User' }],
|
|
294
|
+
* '/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
|
|
295
|
+
* },
|
|
296
|
+
* actions: {
|
|
297
|
+
* '/users': {
|
|
298
|
+
* POST: ({ formData }) => ({ id: crypto.randomUUID(), name: formData?.get('name') }),
|
|
299
|
+
* },
|
|
300
|
+
* '/users/:id': {
|
|
301
|
+
* PUT: ({ formData }) => ({ updated: true }),
|
|
302
|
+
* DELETE: ({ params }) => ({ deleted: true, id: params.id }),
|
|
303
|
+
* },
|
|
304
|
+
* },
|
|
305
|
+
* })
|
|
306
|
+
*/
|
|
307
|
+
declare function createFixtureStore(config?: FixtureStoreConfig): FixtureStore;
|
|
308
|
+
/**
|
|
309
|
+
* Define loader fixtures with type inference
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* const loaders = defineRemixLoaderFixtures({
|
|
313
|
+
* '/users': [{ id: '1', name: 'Demo User' }],
|
|
314
|
+
* '/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
|
|
315
|
+
* '/projects': async () => fetchDemoProjects(),
|
|
316
|
+
* })
|
|
317
|
+
*/
|
|
318
|
+
declare function defineRemixLoaderFixtures<T extends LoaderFixtureMapObject>(fixtures: T): T;
|
|
319
|
+
/**
|
|
320
|
+
* Define action fixtures with type inference
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* const actions = defineRemixActionFixtures({
|
|
324
|
+
* '/users': {
|
|
325
|
+
* POST: ({ formData }) => ({ id: crypto.randomUUID(), name: formData?.get('name') }),
|
|
326
|
+
* },
|
|
327
|
+
* '/users/:id': {
|
|
328
|
+
* PUT: ({ formData }) => ({ updated: true }),
|
|
329
|
+
* DELETE: ({ params }) => ({ deleted: true, id: params.id }),
|
|
330
|
+
* },
|
|
331
|
+
* })
|
|
332
|
+
*/
|
|
333
|
+
declare function defineRemixActionFixtures<T extends ActionFixtureMapObject>(fixtures: T): T;
|
|
334
|
+
/**
|
|
335
|
+
* Define complete Remix fixtures (loaders + actions)
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* const { loaders, actions } = defineRemixFixtures({
|
|
339
|
+
* loaders: {
|
|
340
|
+
* '/users': [{ id: '1', name: 'Demo User' }],
|
|
341
|
+
* },
|
|
342
|
+
* actions: {
|
|
343
|
+
* '/users': ({ formData }) => ({ created: true }),
|
|
344
|
+
* },
|
|
345
|
+
* })
|
|
346
|
+
*/
|
|
347
|
+
declare function defineRemixFixtures<L extends LoaderFixtureMapObject, A extends ActionFixtureMapObject>(config: {
|
|
348
|
+
loaders?: L;
|
|
349
|
+
actions?: A;
|
|
350
|
+
}): {
|
|
351
|
+
loaders: L;
|
|
352
|
+
actions: A;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export { type ActionFixtureHandler as A, type CreateDemoLoaderOptions as C, type DemoRemixProviderProps as D, FixtureStore as F, type LoaderFixtureHandler as L, type MethodActionHandlers as M, type RemixResponse as R, type CreateDemoActionOptions as a, type DemoRemixState as b, createFixtureStore as c, defineRemixLoaderFixtures as d, defineRemixActionFixtures as e, defineRemixFixtures as f, type LoaderFixtureContext as g, type ActionFixtureContext as h, type LoaderFixtureMap as i, type LoaderFixtureMapObject as j, type ActionFixtureMap as k, type ActionFixtureMapObject as l, type DemoRouteOptions as m, type DemoRemixProviderConfig as n, type DemoModeOptions as o, type FixtureStoreConfig as p };
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { MatchResult } from '@demokit-ai/core';
|
|
2
|
+
import { LoaderFunctionArgs, ActionFunctionArgs, TypedResponse } from '@remix-run/node';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context passed to loader fixture handlers
|
|
6
|
+
*/
|
|
7
|
+
interface LoaderFixtureContext {
|
|
8
|
+
/** Route params extracted from the URL */
|
|
9
|
+
params: Record<string, string | undefined>;
|
|
10
|
+
/** The original request object */
|
|
11
|
+
request: Request;
|
|
12
|
+
/** Matched route path pattern */
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Context passed to action fixture handlers
|
|
17
|
+
*/
|
|
18
|
+
interface ActionFixtureContext {
|
|
19
|
+
/** Route params extracted from the URL */
|
|
20
|
+
params: Record<string, string | undefined>;
|
|
21
|
+
/** The original request object */
|
|
22
|
+
request: Request;
|
|
23
|
+
/** Matched route path pattern */
|
|
24
|
+
path: string;
|
|
25
|
+
/** Parsed form data (convenience method result) */
|
|
26
|
+
formData?: FormData;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Loader fixture handler function or static value
|
|
30
|
+
*/
|
|
31
|
+
type LoaderFixtureHandler<T = unknown> = T | ((context: LoaderFixtureContext) => T | Promise<T>);
|
|
32
|
+
/**
|
|
33
|
+
* Action fixture handler function or static value
|
|
34
|
+
*/
|
|
35
|
+
type ActionFixtureHandler<T = unknown> = T | ((context: ActionFixtureContext) => T | Promise<T>);
|
|
36
|
+
/**
|
|
37
|
+
* Map of route paths to loader fixtures
|
|
38
|
+
*
|
|
39
|
+
* Keys are route path patterns like '/users/:id' or '/projects'
|
|
40
|
+
*/
|
|
41
|
+
type LoaderFixtureMap = Map<string, LoaderFixtureHandler>;
|
|
42
|
+
/**
|
|
43
|
+
* Object-based loader fixture map for easier definition
|
|
44
|
+
*/
|
|
45
|
+
type LoaderFixtureMapObject = Record<string, LoaderFixtureHandler>;
|
|
46
|
+
/**
|
|
47
|
+
* Map of route paths to action fixtures
|
|
48
|
+
*
|
|
49
|
+
* Keys are route path patterns like '/users/:id' or '/projects'
|
|
50
|
+
* Values can be keyed by HTTP method: { POST: handler, PUT: handler }
|
|
51
|
+
*/
|
|
52
|
+
type ActionFixtureMap = Map<string, ActionFixtureHandler | MethodActionHandlers>;
|
|
53
|
+
/**
|
|
54
|
+
* Object-based action fixture map for easier definition
|
|
55
|
+
*/
|
|
56
|
+
type ActionFixtureMapObject = Record<string, ActionFixtureHandler | MethodActionHandlers>;
|
|
57
|
+
/**
|
|
58
|
+
* Action handlers organized by HTTP method
|
|
59
|
+
*/
|
|
60
|
+
interface MethodActionHandlers {
|
|
61
|
+
POST?: ActionFixtureHandler;
|
|
62
|
+
PUT?: ActionFixtureHandler;
|
|
63
|
+
PATCH?: ActionFixtureHandler;
|
|
64
|
+
DELETE?: ActionFixtureHandler;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Options for creating a demo-aware loader
|
|
68
|
+
*/
|
|
69
|
+
interface CreateDemoLoaderOptions<T = unknown> {
|
|
70
|
+
/**
|
|
71
|
+
* The real loader function to use when demo mode is disabled
|
|
72
|
+
*/
|
|
73
|
+
loader: (args: LoaderFunctionArgs) => T | Promise<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Function to check if demo mode is enabled
|
|
76
|
+
* Can check cookies, headers, or environment variables
|
|
77
|
+
* @default () => false
|
|
78
|
+
*/
|
|
79
|
+
isEnabled?: (request: Request) => boolean | Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Demo fixture to return when demo mode is enabled
|
|
82
|
+
* Can be a static value or a function
|
|
83
|
+
*/
|
|
84
|
+
fixture?: LoaderFixtureHandler<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Simulated delay in milliseconds
|
|
87
|
+
* @default 0
|
|
88
|
+
*/
|
|
89
|
+
delay?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Callback when demo mode is used
|
|
92
|
+
*/
|
|
93
|
+
onDemo?: (context: LoaderFixtureContext) => void;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options for creating a demo-aware action
|
|
97
|
+
*/
|
|
98
|
+
interface CreateDemoActionOptions<T = unknown> {
|
|
99
|
+
/**
|
|
100
|
+
* The real action function to use when demo mode is disabled
|
|
101
|
+
*/
|
|
102
|
+
action: (args: ActionFunctionArgs) => T | Promise<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Function to check if demo mode is enabled
|
|
105
|
+
* Can check cookies, headers, or environment variables
|
|
106
|
+
* @default () => false
|
|
107
|
+
*/
|
|
108
|
+
isEnabled?: (request: Request) => boolean | Promise<boolean>;
|
|
109
|
+
/**
|
|
110
|
+
* Demo fixture to return when demo mode is enabled
|
|
111
|
+
* Can be a static value, a function, or organized by HTTP method
|
|
112
|
+
*/
|
|
113
|
+
fixture?: ActionFixtureHandler<T> | MethodActionHandlers;
|
|
114
|
+
/**
|
|
115
|
+
* Simulated delay in milliseconds
|
|
116
|
+
* @default 0
|
|
117
|
+
*/
|
|
118
|
+
delay?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Callback when demo mode is used
|
|
121
|
+
*/
|
|
122
|
+
onDemo?: (context: ActionFixtureContext) => void;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Options for the demo route wrapper
|
|
126
|
+
*/
|
|
127
|
+
interface DemoRouteOptions {
|
|
128
|
+
/**
|
|
129
|
+
* Function to check if demo mode is enabled
|
|
130
|
+
*/
|
|
131
|
+
isEnabled?: (request: Request) => boolean | Promise<boolean>;
|
|
132
|
+
/**
|
|
133
|
+
* Default delay for all fixtures
|
|
134
|
+
*/
|
|
135
|
+
delay?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Loader fixtures by path
|
|
138
|
+
*/
|
|
139
|
+
loaders?: LoaderFixtureMapObject;
|
|
140
|
+
/**
|
|
141
|
+
* Action fixtures by path
|
|
142
|
+
*/
|
|
143
|
+
actions?: ActionFixtureMapObject;
|
|
144
|
+
/**
|
|
145
|
+
* Callback when no fixture is found
|
|
146
|
+
*/
|
|
147
|
+
onMissing?: (type: 'loader' | 'action', path: string) => void;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* State for the demo remix context
|
|
151
|
+
*/
|
|
152
|
+
interface DemoRemixState {
|
|
153
|
+
/** Whether demo mode is enabled */
|
|
154
|
+
enabled: boolean;
|
|
155
|
+
/** Current loader fixtures */
|
|
156
|
+
loaders: LoaderFixtureMap;
|
|
157
|
+
/** Current action fixtures */
|
|
158
|
+
actions: ActionFixtureMap;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provider configuration
|
|
162
|
+
*/
|
|
163
|
+
interface DemoRemixProviderConfig {
|
|
164
|
+
/**
|
|
165
|
+
* Whether demo mode is enabled
|
|
166
|
+
* @default false
|
|
167
|
+
*/
|
|
168
|
+
enabled?: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Loader fixtures
|
|
171
|
+
*/
|
|
172
|
+
loaders?: LoaderFixtureMapObject;
|
|
173
|
+
/**
|
|
174
|
+
* Action fixtures
|
|
175
|
+
*/
|
|
176
|
+
actions?: ActionFixtureMapObject;
|
|
177
|
+
/**
|
|
178
|
+
* Simulated delay in milliseconds
|
|
179
|
+
* @default 0
|
|
180
|
+
*/
|
|
181
|
+
delay?: number;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Props for DemoRemixProvider
|
|
185
|
+
*/
|
|
186
|
+
interface DemoRemixProviderProps extends DemoRemixProviderConfig {
|
|
187
|
+
children: React.ReactNode;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Demo mode detection options
|
|
191
|
+
*/
|
|
192
|
+
interface DemoModeOptions {
|
|
193
|
+
/**
|
|
194
|
+
* Cookie name to check for demo mode
|
|
195
|
+
* @default 'demokit-demo-mode'
|
|
196
|
+
*/
|
|
197
|
+
cookieName?: string;
|
|
198
|
+
/**
|
|
199
|
+
* Header name to check for demo mode
|
|
200
|
+
* @default 'x-demokit-demo-mode'
|
|
201
|
+
*/
|
|
202
|
+
headerName?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Environment variable to check for demo mode
|
|
205
|
+
* @default 'DEMOKIT_DEMO_MODE'
|
|
206
|
+
*/
|
|
207
|
+
envVar?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Query parameter to check for demo mode
|
|
210
|
+
* @default 'demo'
|
|
211
|
+
*/
|
|
212
|
+
queryParam?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Server-side fixture store configuration
|
|
216
|
+
*/
|
|
217
|
+
interface FixtureStoreConfig {
|
|
218
|
+
/**
|
|
219
|
+
* Loader fixtures by route path
|
|
220
|
+
*/
|
|
221
|
+
loaders?: LoaderFixtureMapObject;
|
|
222
|
+
/**
|
|
223
|
+
* Action fixtures by route path
|
|
224
|
+
*/
|
|
225
|
+
actions?: ActionFixtureMapObject;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Result type from Remix loaders/actions (supports json, defer, redirect)
|
|
229
|
+
*/
|
|
230
|
+
type RemixResponse<T> = T | TypedResponse<T>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Server-side fixture store for managing demo data
|
|
234
|
+
*
|
|
235
|
+
* Use this to centralize fixture definitions for your Remix app.
|
|
236
|
+
* Works with the demo mode detection utilities.
|
|
237
|
+
*/
|
|
238
|
+
declare class FixtureStore {
|
|
239
|
+
private loaders;
|
|
240
|
+
private actions;
|
|
241
|
+
constructor(config?: FixtureStoreConfig);
|
|
242
|
+
/**
|
|
243
|
+
* Register a loader fixture
|
|
244
|
+
*/
|
|
245
|
+
setLoader(path: string, handler: LoaderFixtureHandler): this;
|
|
246
|
+
/**
|
|
247
|
+
* Register an action fixture
|
|
248
|
+
*/
|
|
249
|
+
setAction(path: string, handler: ActionFixtureHandler | MethodActionHandlers): this;
|
|
250
|
+
/**
|
|
251
|
+
* Get a loader fixture for a path
|
|
252
|
+
*/
|
|
253
|
+
getLoader(path: string): LoaderFixtureHandler | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Get an action fixture for a path and method
|
|
256
|
+
*/
|
|
257
|
+
getAction(path: string, method: string): ActionFixtureHandler | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Find loader fixture with match info
|
|
260
|
+
*/
|
|
261
|
+
findLoader(path: string): {
|
|
262
|
+
handler: LoaderFixtureHandler;
|
|
263
|
+
match: MatchResult;
|
|
264
|
+
} | null;
|
|
265
|
+
/**
|
|
266
|
+
* Find action fixture with match info
|
|
267
|
+
*/
|
|
268
|
+
findAction(path: string, method: string): {
|
|
269
|
+
handler: ActionFixtureHandler;
|
|
270
|
+
match: MatchResult;
|
|
271
|
+
} | null;
|
|
272
|
+
/**
|
|
273
|
+
* Get all loader fixtures
|
|
274
|
+
*/
|
|
275
|
+
getLoaders(): LoaderFixtureMapObject;
|
|
276
|
+
/**
|
|
277
|
+
* Get all action fixtures
|
|
278
|
+
*/
|
|
279
|
+
getActions(): ActionFixtureMapObject;
|
|
280
|
+
/**
|
|
281
|
+
* Clear all fixtures
|
|
282
|
+
*/
|
|
283
|
+
clear(): void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Create a fixture store with initial fixtures
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* import { createFixtureStore } from '@demokit-ai/remix/server'
|
|
290
|
+
*
|
|
291
|
+
* export const fixtures = createFixtureStore({
|
|
292
|
+
* loaders: {
|
|
293
|
+
* '/users': [{ id: '1', name: 'Demo User' }],
|
|
294
|
+
* '/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
|
|
295
|
+
* },
|
|
296
|
+
* actions: {
|
|
297
|
+
* '/users': {
|
|
298
|
+
* POST: ({ formData }) => ({ id: crypto.randomUUID(), name: formData?.get('name') }),
|
|
299
|
+
* },
|
|
300
|
+
* '/users/:id': {
|
|
301
|
+
* PUT: ({ formData }) => ({ updated: true }),
|
|
302
|
+
* DELETE: ({ params }) => ({ deleted: true, id: params.id }),
|
|
303
|
+
* },
|
|
304
|
+
* },
|
|
305
|
+
* })
|
|
306
|
+
*/
|
|
307
|
+
declare function createFixtureStore(config?: FixtureStoreConfig): FixtureStore;
|
|
308
|
+
/**
|
|
309
|
+
* Define loader fixtures with type inference
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* const loaders = defineRemixLoaderFixtures({
|
|
313
|
+
* '/users': [{ id: '1', name: 'Demo User' }],
|
|
314
|
+
* '/users/:id': ({ params }) => ({ id: params.id, name: 'Demo User' }),
|
|
315
|
+
* '/projects': async () => fetchDemoProjects(),
|
|
316
|
+
* })
|
|
317
|
+
*/
|
|
318
|
+
declare function defineRemixLoaderFixtures<T extends LoaderFixtureMapObject>(fixtures: T): T;
|
|
319
|
+
/**
|
|
320
|
+
* Define action fixtures with type inference
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* const actions = defineRemixActionFixtures({
|
|
324
|
+
* '/users': {
|
|
325
|
+
* POST: ({ formData }) => ({ id: crypto.randomUUID(), name: formData?.get('name') }),
|
|
326
|
+
* },
|
|
327
|
+
* '/users/:id': {
|
|
328
|
+
* PUT: ({ formData }) => ({ updated: true }),
|
|
329
|
+
* DELETE: ({ params }) => ({ deleted: true, id: params.id }),
|
|
330
|
+
* },
|
|
331
|
+
* })
|
|
332
|
+
*/
|
|
333
|
+
declare function defineRemixActionFixtures<T extends ActionFixtureMapObject>(fixtures: T): T;
|
|
334
|
+
/**
|
|
335
|
+
* Define complete Remix fixtures (loaders + actions)
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* const { loaders, actions } = defineRemixFixtures({
|
|
339
|
+
* loaders: {
|
|
340
|
+
* '/users': [{ id: '1', name: 'Demo User' }],
|
|
341
|
+
* },
|
|
342
|
+
* actions: {
|
|
343
|
+
* '/users': ({ formData }) => ({ created: true }),
|
|
344
|
+
* },
|
|
345
|
+
* })
|
|
346
|
+
*/
|
|
347
|
+
declare function defineRemixFixtures<L extends LoaderFixtureMapObject, A extends ActionFixtureMapObject>(config: {
|
|
348
|
+
loaders?: L;
|
|
349
|
+
actions?: A;
|
|
350
|
+
}): {
|
|
351
|
+
loaders: L;
|
|
352
|
+
actions: A;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
export { type ActionFixtureHandler as A, type CreateDemoLoaderOptions as C, type DemoRemixProviderProps as D, FixtureStore as F, type LoaderFixtureHandler as L, type MethodActionHandlers as M, type RemixResponse as R, type CreateDemoActionOptions as a, type DemoRemixState as b, createFixtureStore as c, defineRemixLoaderFixtures as d, defineRemixActionFixtures as e, defineRemixFixtures as f, type LoaderFixtureContext as g, type ActionFixtureContext as h, type LoaderFixtureMap as i, type LoaderFixtureMapObject as j, type ActionFixtureMap as k, type ActionFixtureMapObject as l, type DemoRouteOptions as m, type DemoRemixProviderConfig as n, type DemoModeOptions as o, type FixtureStoreConfig as p };
|