schemock 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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +82 -0
  3. package/dist/adapters/index.d.mts +1364 -0
  4. package/dist/adapters/index.d.ts +1364 -0
  5. package/dist/adapters/index.js +36988 -0
  6. package/dist/adapters/index.js.map +1 -0
  7. package/dist/adapters/index.mjs +36972 -0
  8. package/dist/adapters/index.mjs.map +1 -0
  9. package/dist/cli/index.d.mts +831 -0
  10. package/dist/cli/index.d.ts +831 -0
  11. package/dist/cli/index.js +4425 -0
  12. package/dist/cli/index.js.map +1 -0
  13. package/dist/cli/index.mjs +4401 -0
  14. package/dist/cli/index.mjs.map +1 -0
  15. package/dist/cli.js +6776 -0
  16. package/dist/index.d.mts +8 -0
  17. package/dist/index.d.ts +8 -0
  18. package/dist/index.js +39439 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.mjs +39367 -0
  21. package/dist/index.mjs.map +1 -0
  22. package/dist/middleware/index.d.mts +688 -0
  23. package/dist/middleware/index.d.ts +688 -0
  24. package/dist/middleware/index.js +921 -0
  25. package/dist/middleware/index.js.map +1 -0
  26. package/dist/middleware/index.mjs +899 -0
  27. package/dist/middleware/index.mjs.map +1 -0
  28. package/dist/react/index.d.mts +316 -0
  29. package/dist/react/index.d.ts +316 -0
  30. package/dist/react/index.js +466 -0
  31. package/dist/react/index.js.map +1 -0
  32. package/dist/react/index.mjs +456 -0
  33. package/dist/react/index.mjs.map +1 -0
  34. package/dist/runtime/index.d.mts +814 -0
  35. package/dist/runtime/index.d.ts +814 -0
  36. package/dist/runtime/index.js +1270 -0
  37. package/dist/runtime/index.js.map +1 -0
  38. package/dist/runtime/index.mjs +1246 -0
  39. package/dist/runtime/index.mjs.map +1 -0
  40. package/dist/schema/index.d.mts +838 -0
  41. package/dist/schema/index.d.ts +838 -0
  42. package/dist/schema/index.js +696 -0
  43. package/dist/schema/index.js.map +1 -0
  44. package/dist/schema/index.mjs +681 -0
  45. package/dist/schema/index.mjs.map +1 -0
  46. package/dist/types-C1MiZh1d.d.ts +96 -0
  47. package/dist/types-C2bd2vgy.d.mts +773 -0
  48. package/dist/types-C2bd2vgy.d.ts +773 -0
  49. package/dist/types-C9VMgu3E.d.mts +289 -0
  50. package/dist/types-DV2DS7wj.d.mts +96 -0
  51. package/dist/types-c2AN3vky.d.ts +289 -0
  52. package/package.json +116 -0
@@ -0,0 +1,814 @@
1
+ import { o as EntitySchema, s as ViewSchema, c as RelationDefinition, C as ComputedFieldDefinition } from '../types-C2bd2vgy.js';
2
+ import { A as Adapter } from '../types-c2AN3vky.js';
3
+ import { HttpHandler } from 'msw';
4
+
5
+ /**
6
+ * Schema Registry - Manages schema registration and lookup
7
+ *
8
+ * @module runtime/resolver/registry
9
+ * @category Runtime
10
+ */
11
+
12
+ /**
13
+ * Schema Registry manages all registered entity and view schemas.
14
+ * Provides fast lookup and traversal of schema metadata.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { SchemaRegistry } from 'schemock/runtime';
19
+ *
20
+ * const registry = new SchemaRegistry();
21
+ * registry.register(UserSchema);
22
+ * registry.register(PostSchema);
23
+ *
24
+ * const user = registry.get('user');
25
+ * ```
26
+ */
27
+ declare class SchemaRegistry {
28
+ private entities;
29
+ private views;
30
+ /**
31
+ * Register an entity schema
32
+ * @param schema - The entity schema to register
33
+ */
34
+ register(schema: EntitySchema): void;
35
+ /**
36
+ * Register a view schema
37
+ * @param view - The view schema to register
38
+ */
39
+ registerView(view: ViewSchema): void;
40
+ /**
41
+ * Get an entity schema by name
42
+ * @param entityName - The entity name
43
+ * @returns EntitySchema or undefined if not found
44
+ */
45
+ get(entityName: string): EntitySchema | undefined;
46
+ /**
47
+ * Get an entity schema by name, throws if not found
48
+ * @param entityName - The entity name
49
+ * @returns EntitySchema
50
+ * @throws Error if entity not found
51
+ */
52
+ getOrThrow(entityName: string): EntitySchema;
53
+ /**
54
+ * Get a view schema by name
55
+ * @param viewName - The view name
56
+ * @returns ViewSchema or undefined if not found
57
+ */
58
+ getView(viewName: string): ViewSchema | undefined;
59
+ /**
60
+ * Get a view schema by name, throws if not found
61
+ * @param viewName - The view name
62
+ * @returns ViewSchema
63
+ * @throws Error if view not found
64
+ */
65
+ getViewOrThrow(viewName: string): ViewSchema;
66
+ /**
67
+ * Get all registered entity schemas
68
+ * @returns Array of all entity schemas
69
+ */
70
+ getAll(): EntitySchema[];
71
+ /**
72
+ * Get all registered view schemas
73
+ * @returns Array of all view schemas
74
+ */
75
+ getAllViews(): ViewSchema[];
76
+ /**
77
+ * Check if an entity schema is registered
78
+ * @param entityName - The entity name
79
+ * @returns true if registered
80
+ */
81
+ has(entityName: string): boolean;
82
+ /**
83
+ * Check if a view schema is registered
84
+ * @param viewName - The view name
85
+ * @returns true if registered
86
+ */
87
+ hasView(viewName: string): boolean;
88
+ /**
89
+ * Get all relations for an entity
90
+ * @param entityName - The entity name
91
+ * @returns Array of relation definitions with their names
92
+ */
93
+ getRelationsFor(entityName: string): Array<{
94
+ name: string;
95
+ relation: RelationDefinition;
96
+ }>;
97
+ /**
98
+ * Get all entities that have a relation to a target entity
99
+ * @param targetEntityName - The target entity name
100
+ * @returns Array of entity names that reference the target
101
+ */
102
+ getEntitiesReferencingEntity(targetEntityName: string): string[];
103
+ /**
104
+ * Get entity names in dependency order (topological sort)
105
+ * Entities with no dependencies come first
106
+ * @returns Array of entity names in order
107
+ */
108
+ getEntityOrder(): string[];
109
+ /**
110
+ * Clear all registered schemas
111
+ */
112
+ clear(): void;
113
+ /**
114
+ * Get entity count
115
+ */
116
+ get entityCount(): number;
117
+ /**
118
+ * Get view count
119
+ */
120
+ get viewCount(): number;
121
+ }
122
+ /**
123
+ * Global schema registry instance
124
+ */
125
+ declare const registry: SchemaRegistry;
126
+
127
+ /**
128
+ * Computed Field Resolver - Handles resolution of computed/derived fields
129
+ *
130
+ * @module runtime/resolver/computed
131
+ * @category Runtime
132
+ */
133
+
134
+ /**
135
+ * Context passed to computed field resolvers
136
+ */
137
+ interface ResolverContext {
138
+ /** Current user ID for auth-related computations */
139
+ currentUserId?: string;
140
+ /** Request parameters */
141
+ params?: Record<string, unknown>;
142
+ /** Request headers */
143
+ headers?: Record<string, string>;
144
+ /** Mode: 'seed' uses mock(), 'resolve' uses resolve() */
145
+ mode: 'seed' | 'resolve';
146
+ }
147
+ /**
148
+ * Database entity operations interface
149
+ */
150
+ interface DatabaseEntity {
151
+ findFirst(query: unknown): unknown;
152
+ findMany(query: unknown): unknown[];
153
+ count(query?: unknown): number;
154
+ create?(data: unknown): unknown;
155
+ update?(query: unknown): unknown;
156
+ delete?(query: unknown): unknown;
157
+ }
158
+ /**
159
+ * Generic database interface for computed field resolvers
160
+ */
161
+ interface Database {
162
+ [entityName: string]: DatabaseEntity;
163
+ }
164
+ /**
165
+ * Sorts computed fields by their dependencies using topological sort.
166
+ * Fields with no dependencies come first, fields that depend on others come later.
167
+ *
168
+ * @param fields - Array of [fieldName, definition] tuples to sort
169
+ * @param allComputed - Full record of all computed field definitions
170
+ * @returns Sorted array of [fieldName, definition] tuples
171
+ * @throws Error if circular dependency is detected
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * const fields = [
176
+ * ['avgViews', { dependsOn: ['totalViews', 'postCount'] }],
177
+ * ['postCount', { dependsOn: [] }],
178
+ * ['totalViews', { dependsOn: ['postCount'] }],
179
+ * ];
180
+ *
181
+ * const sorted = topologicalSort(fields, allComputed);
182
+ * // Returns: [['postCount', ...], ['totalViews', ...], ['avgViews', ...]]
183
+ * ```
184
+ */
185
+ declare function topologicalSort<T extends ComputedFieldDefinition>(fields: Array<[string, T]>, allComputed: Record<string, ComputedFieldDefinition>): Array<[string, T]>;
186
+ /**
187
+ * Clears the compute cache. Should be called at the start of each request.
188
+ */
189
+ declare function clearComputeCache(): void;
190
+ /**
191
+ * Resolves a single computed field for an entity.
192
+ *
193
+ * @param entity - The entity to compute the field for
194
+ * @param fieldName - The name of the computed field
195
+ * @param computed - The computed field definition
196
+ * @param db - Database interface for queries
197
+ * @param context - Resolver context
198
+ * @returns The computed value
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const postCount = resolveComputedField(
203
+ * user,
204
+ * 'postCount',
205
+ * { resolve: (user, db) => db.post.count({ where: { authorId: user.id } }) },
206
+ * db,
207
+ * { mode: 'resolve' }
208
+ * );
209
+ * ```
210
+ */
211
+ declare function resolveComputedField<T>(entity: Record<string, unknown>, fieldName: string, computed: ComputedFieldDefinition<T>, db: Database, context: ResolverContext): T | Promise<T>;
212
+ /**
213
+ * Resolves all computed fields for an entity.
214
+ * Fields are resolved in dependency order.
215
+ *
216
+ * @param entity - The entity to resolve computed fields for
217
+ * @param schema - The entity schema
218
+ * @param db - Database interface for queries
219
+ * @param context - Resolver context
220
+ * @returns The entity with computed fields resolved (mutates and returns the same object)
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const user = await resolveComputedFields(rawUser, UserSchema, db, { mode: 'resolve' });
225
+ * console.log(user.postCount); // Now available
226
+ * ```
227
+ */
228
+ declare function resolveComputedFields<T extends Record<string, unknown>>(entity: T, schema: EntitySchema, db: Database, context: ResolverContext): Promise<T>;
229
+ /**
230
+ * Resolves computed fields synchronously (for mock mode where all mocks are sync)
231
+ *
232
+ * @param entity - The entity to resolve computed fields for
233
+ * @param schema - The entity schema
234
+ * @param context - Resolver context (should have mode: 'seed')
235
+ * @returns The entity with computed fields resolved
236
+ */
237
+ declare function resolveComputedFieldsSync<T extends Record<string, unknown>>(entity: T, schema: EntitySchema, context: ResolverContext): T;
238
+
239
+ /**
240
+ * Relation Resolver - Handles lazy and eager loading of entity relations
241
+ *
242
+ * @module runtime/resolver/relation
243
+ * @category Runtime
244
+ */
245
+
246
+ /**
247
+ * Options for resolving relations
248
+ */
249
+ interface ResolveRelationOptions {
250
+ /** Specific relations to include (by name or nested path like 'posts.comments') */
251
+ include?: string[];
252
+ /** Maximum depth for nested relation resolution */
253
+ depth?: number;
254
+ /** Default limit for hasMany relations */
255
+ limit?: number;
256
+ /** Default ordering for hasMany relations */
257
+ orderBy?: Record<string, 'asc' | 'desc'>;
258
+ }
259
+ /**
260
+ * Resolves a single relation for an entity.
261
+ *
262
+ * @param entity - The source entity
263
+ * @param relationName - Name of the relation field
264
+ * @param relation - The relation definition
265
+ * @param db - Database interface
266
+ * @param registry - Schema registry
267
+ * @param options - Resolution options
268
+ * @param currentDepth - Current recursion depth
269
+ * @returns The related entity/entities or null/empty array
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * const posts = await resolveRelation(
274
+ * user,
275
+ * 'posts',
276
+ * { type: 'hasMany', target: 'post', foreignKey: 'authorId' },
277
+ * db,
278
+ * registry,
279
+ * { limit: 10 }
280
+ * );
281
+ * ```
282
+ */
283
+ declare function resolveRelation<T>(entity: Record<string, unknown>, relationName: string, relation: RelationDefinition, db: Database, registry: SchemaRegistry, options?: ResolveRelationOptions, currentDepth?: number): Promise<T | T[] | null>;
284
+ /**
285
+ * Resolves all relations for an entity.
286
+ *
287
+ * @param entity - The entity to resolve relations for
288
+ * @param schema - The entity schema
289
+ * @param db - Database interface
290
+ * @param registry - Schema registry
291
+ * @param options - Resolution options
292
+ * @returns The entity with relations resolved (mutates and returns same object)
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * const user = await resolveRelations(rawUser, UserSchema, db, registry, {
297
+ * include: ['profile', 'posts', 'posts.comments'],
298
+ * });
299
+ * ```
300
+ */
301
+ declare function resolveRelations<T extends Record<string, unknown>>(entity: T, schema: EntitySchema, db: Database, registry: SchemaRegistry, options?: ResolveRelationOptions): Promise<T>;
302
+ /**
303
+ * Eagerly loads relations for multiple entities (batch loading).
304
+ * More efficient than loading relations one-by-one.
305
+ *
306
+ * @param entities - Array of entities to load relations for
307
+ * @param schema - The entity schema
308
+ * @param db - Database interface
309
+ * @param registry - Schema registry
310
+ * @param options - Resolution options
311
+ * @returns The entities with relations resolved
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * const users = await eagerLoadRelations(rawUsers, UserSchema, db, registry, {
316
+ * include: ['profile'],
317
+ * });
318
+ * ```
319
+ */
320
+ declare function eagerLoadRelations<T extends Record<string, unknown>>(entities: T[], schema: EntitySchema, db: Database, registry: SchemaRegistry, options?: ResolveRelationOptions): Promise<T[]>;
321
+
322
+ /**
323
+ * View Resolver - Executes view queries by applying filters and transforms
324
+ *
325
+ * @module runtime/resolver/view
326
+ * @category Runtime
327
+ */
328
+
329
+ /**
330
+ * Options for resolving a view
331
+ */
332
+ interface ViewResolveOptions {
333
+ /** URL parameters */
334
+ params: Record<string, string>;
335
+ /** Resolver context */
336
+ context: ResolverContext;
337
+ }
338
+ /**
339
+ * ViewResolver handles resolution of view schemas.
340
+ * Views are computed projections over entity data.
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * const viewResolver = new ViewResolver(registry, db);
345
+ * const userFull = await viewResolver.resolve(UserFullView, { id: '123' });
346
+ * ```
347
+ */
348
+ declare class ViewResolver {
349
+ private registry;
350
+ private db;
351
+ constructor(registry: SchemaRegistry, db: Database);
352
+ /**
353
+ * Resolves a view schema with given parameters.
354
+ *
355
+ * @param view - The view schema to resolve
356
+ * @param params - URL parameters for the view
357
+ * @param context - Optional resolver context
358
+ * @returns The resolved view data
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * const userData = await viewResolver.resolve(UserFullView, { id: 'user-123' });
363
+ * ```
364
+ */
365
+ resolve<T>(view: ViewSchema, params: Record<string, string>, context?: Partial<ResolverContext>): Promise<T>;
366
+ /**
367
+ * Builds the view result by resolving all fields
368
+ */
369
+ private buildViewResult;
370
+ /**
371
+ * Check if a field definition is a nested object
372
+ */
373
+ private isNestedObjectField;
374
+ /**
375
+ * Resolves an embedded entity field
376
+ */
377
+ private resolveEmbed;
378
+ /**
379
+ * Guess the parent entity name from the view endpoint
380
+ */
381
+ private guessParentEntityName;
382
+ /**
383
+ * Resolves a computed field within a view context
384
+ */
385
+ private resolveViewComputedField;
386
+ /**
387
+ * Resolves a nested object containing fields and computed values
388
+ */
389
+ private resolveNestedObject;
390
+ /**
391
+ * Resolves a view with mock data (for seeding)
392
+ */
393
+ resolveMock<T>(view: ViewSchema, params: Record<string, string>): Promise<T>;
394
+ }
395
+ /**
396
+ * Creates a new ViewResolver instance
397
+ *
398
+ * @param registry - Schema registry
399
+ * @param db - Database interface
400
+ * @returns ViewResolver instance
401
+ */
402
+ declare function createViewResolver(registry: SchemaRegistry, db: Database): ViewResolver;
403
+
404
+ /**
405
+ * Main Resolver Engine - Core CRUD operations with relation and computed field resolution
406
+ *
407
+ * @module runtime/resolver
408
+ * @category Runtime
409
+ */
410
+
411
+ /**
412
+ * Options for single entity queries
413
+ */
414
+ interface EntityQueryOptions extends ResolveRelationOptions {
415
+ /** Filter conditions */
416
+ where?: Record<string, unknown>;
417
+ /** Specific computed fields to resolve */
418
+ computed?: string[];
419
+ }
420
+ /**
421
+ * Options for list queries
422
+ */
423
+ interface ListQueryOptions extends EntityQueryOptions {
424
+ /** Maximum number of results */
425
+ limit?: number;
426
+ /** Number of results to skip (for pagination) */
427
+ offset?: number;
428
+ /** Sort order */
429
+ orderBy?: Record<string, 'asc' | 'desc'>;
430
+ }
431
+ /**
432
+ * Options for count queries
433
+ */
434
+ interface CountOptions {
435
+ /** Filter conditions */
436
+ where?: Record<string, unknown>;
437
+ }
438
+ /**
439
+ * Create input type (partial entity without id)
440
+ */
441
+ type CreateInput<T> = Omit<Partial<T>, 'id'>;
442
+ /**
443
+ * Update input type (partial entity)
444
+ */
445
+ type UpdateInput<T> = Partial<T>;
446
+ /**
447
+ * Main resolver engine for CRUD operations.
448
+ * Orchestrates relation loading, computed field resolution, and database queries.
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * const resolver = new Resolver(registry, db);
453
+ *
454
+ * // Find one with relations
455
+ * const user = await resolver.findOne('user', '123', {
456
+ * include: ['profile', 'posts'],
457
+ * });
458
+ *
459
+ * // Find many with pagination
460
+ * const users = await resolver.findMany('user', {
461
+ * limit: 20,
462
+ * offset: 0,
463
+ * orderBy: { createdAt: 'desc' },
464
+ * });
465
+ * ```
466
+ */
467
+ declare class Resolver {
468
+ private registry;
469
+ private db;
470
+ private context;
471
+ private viewResolver;
472
+ constructor(registry: SchemaRegistry, db: Database, context?: Partial<ResolverContext>);
473
+ /**
474
+ * Find a single entity by ID
475
+ *
476
+ * @param entityName - The entity type to find
477
+ * @param id - The entity ID
478
+ * @param options - Query options (relations, computed fields)
479
+ * @returns The entity or null if not found
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * const user = await resolver.findOne('user', '123', {
484
+ * include: ['profile'],
485
+ * computed: ['postCount'],
486
+ * });
487
+ * ```
488
+ */
489
+ findOne<T extends Record<string, unknown>>(entityName: string, id: string, options?: EntityQueryOptions): Promise<T | null>;
490
+ /**
491
+ * Find multiple entities with filtering and pagination
492
+ *
493
+ * @param entityName - The entity type to find
494
+ * @param options - Query options (filters, pagination, relations)
495
+ * @returns Array of entities
496
+ *
497
+ * @example
498
+ * ```typescript
499
+ * const users = await resolver.findMany('user', {
500
+ * where: { role: 'admin' },
501
+ * limit: 20,
502
+ * offset: 0,
503
+ * include: ['profile'],
504
+ * });
505
+ * ```
506
+ */
507
+ findMany<T extends Record<string, unknown>>(entityName: string, options?: ListQueryOptions): Promise<T[]>;
508
+ /**
509
+ * Create a new entity
510
+ *
511
+ * @param entityName - The entity type to create
512
+ * @param data - The entity data
513
+ * @param options - Query options for the returned entity
514
+ * @returns The created entity with relations and computed fields
515
+ *
516
+ * @example
517
+ * ```typescript
518
+ * const user = await resolver.create('user', {
519
+ * name: 'John Doe',
520
+ * email: 'john@example.com',
521
+ * });
522
+ * ```
523
+ */
524
+ create<T extends Record<string, unknown>>(entityName: string, data: CreateInput<T>, options?: EntityQueryOptions): Promise<T>;
525
+ /**
526
+ * Update an existing entity
527
+ *
528
+ * @param entityName - The entity type to update
529
+ * @param id - The entity ID
530
+ * @param data - The update data
531
+ * @param options - Query options for the returned entity
532
+ * @returns The updated entity or null if not found
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * const user = await resolver.update('user', '123', {
537
+ * name: 'Jane Doe',
538
+ * });
539
+ * ```
540
+ */
541
+ update<T extends Record<string, unknown>>(entityName: string, id: string, data: UpdateInput<T>, options?: EntityQueryOptions): Promise<T | null>;
542
+ /**
543
+ * Delete an entity by ID
544
+ *
545
+ * @param entityName - The entity type to delete
546
+ * @param id - The entity ID
547
+ * @returns true if deleted, false if not found
548
+ *
549
+ * @example
550
+ * ```typescript
551
+ * const deleted = await resolver.delete('user', '123');
552
+ * ```
553
+ */
554
+ delete(entityName: string, id: string): boolean;
555
+ /**
556
+ * Count entities matching a filter
557
+ *
558
+ * @param entityName - The entity type to count
559
+ * @param options - Count options (filters)
560
+ * @returns The count
561
+ *
562
+ * @example
563
+ * ```typescript
564
+ * const adminCount = await resolver.count('user', {
565
+ * where: { role: 'admin' },
566
+ * });
567
+ * ```
568
+ */
569
+ count(entityName: string, options?: CountOptions): number;
570
+ /**
571
+ * Resolve a view with parameters
572
+ *
573
+ * @param viewName - The view name
574
+ * @param params - View parameters
575
+ * @returns The resolved view data
576
+ *
577
+ * @example
578
+ * ```typescript
579
+ * const userFull = await resolver.view('user-full', { id: '123' });
580
+ * ```
581
+ */
582
+ view<T>(viewName: string, params: Record<string, string>): Promise<T | null>;
583
+ /**
584
+ * Build a where clause from simple object to database format
585
+ */
586
+ private buildWhereClause;
587
+ /**
588
+ * Get the current resolver context
589
+ */
590
+ getContext(): ResolverContext;
591
+ /**
592
+ * Create a new resolver with updated context
593
+ */
594
+ withContext(context: Partial<ResolverContext>): Resolver;
595
+ }
596
+ /**
597
+ * Creates a new Resolver instance
598
+ *
599
+ * @param registry - Schema registry
600
+ * @param db - Database interface
601
+ * @param context - Optional resolver context
602
+ * @returns Resolver instance
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * const resolver = createResolver(registry, db, {
607
+ * currentUserId: 'user-123',
608
+ * });
609
+ * ```
610
+ */
611
+ declare function createResolver(registry: SchemaRegistry, db: Database, context?: Partial<ResolverContext>): Resolver;
612
+
613
+ /**
614
+ * Runtime Setup - Initialize mock runtime with MSW worker
615
+ *
616
+ * Provides setup functions for initializing the mock server
617
+ * in both browser and Node.js environments.
618
+ *
619
+ * @module runtime/setup
620
+ * @category Runtime
621
+ */
622
+
623
+ /**
624
+ * Setup options for runtime initialization.
625
+ */
626
+ interface SetupOptions {
627
+ /** The adapter to use */
628
+ adapter: Adapter;
629
+ /** Entity schemas */
630
+ schemas: EntitySchema[];
631
+ /** Whether to start MSW (browser only) */
632
+ startMsw?: boolean;
633
+ /** MSW handler options */
634
+ mswOptions?: {
635
+ /** Base URL for handlers */
636
+ baseUrl?: string;
637
+ /** Whether to log requests */
638
+ quiet?: boolean;
639
+ };
640
+ }
641
+ /**
642
+ * Initialize the mock runtime.
643
+ *
644
+ * Sets up the adapter, registers schemas, and optionally starts
645
+ * the MSW service worker for browser environments.
646
+ *
647
+ * @returns Promise that resolves when setup is complete
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * import { setup } from 'schemock/runtime';
652
+ * import { createMockAdapter } from 'schemock/adapters';
653
+ *
654
+ * await setup({
655
+ * adapter: createMockAdapter([userSchema, postSchema]),
656
+ * schemas: [userSchema, postSchema],
657
+ * startMsw: true,
658
+ * });
659
+ * ```
660
+ */
661
+ declare function setup(options?: SetupOptions): Promise<void>;
662
+ /**
663
+ * Teardown the runtime and clean up resources.
664
+ *
665
+ * @example
666
+ * ```typescript
667
+ * await teardown();
668
+ * ```
669
+ */
670
+ declare function teardown(): Promise<void>;
671
+ /**
672
+ * Check if the runtime is initialized.
673
+ *
674
+ * @returns True if initialized
675
+ */
676
+ declare function isInitialized(): boolean;
677
+ /**
678
+ * Get the active adapter.
679
+ *
680
+ * @returns The adapter or null
681
+ */
682
+ declare function getAdapter(): Adapter | null;
683
+ /**
684
+ * Set the active adapter (for testing or manual configuration).
685
+ *
686
+ * @param adapter - The adapter to set
687
+ */
688
+ declare function setAdapter(adapter: Adapter): void;
689
+
690
+ /**
691
+ * Seed Function - Populate database with fake data
692
+ *
693
+ * Seeds the MockAdapter database with generated fake data
694
+ * based on entity schemas and specified counts.
695
+ *
696
+ * @module runtime/seed
697
+ * @category Runtime
698
+ */
699
+ /**
700
+ * Seed the database with fake data.
701
+ *
702
+ * Uses the configured MockAdapter to generate and persist
703
+ * fake entities based on the provided counts.
704
+ *
705
+ * @param counts - Map of entity names to number of items to create
706
+ *
707
+ * @example
708
+ * ```typescript
709
+ * import { seed } from 'schemock/runtime';
710
+ *
711
+ * // Seed with specific counts
712
+ * seed({
713
+ * user: 10,
714
+ * post: 50,
715
+ * comment: 100,
716
+ * });
717
+ * ```
718
+ *
719
+ * @example
720
+ * ```typescript
721
+ * // Seed in a setup function
722
+ * async function initMockData() {
723
+ * await setup({ adapter, schemas });
724
+ * seed({ user: 5, project: 10 });
725
+ * }
726
+ * ```
727
+ */
728
+ declare function seed(counts: Record<string, number>): void;
729
+ /**
730
+ * Reset the database to empty state.
731
+ *
732
+ * Clears all data from the MockAdapter database.
733
+ *
734
+ * @example
735
+ * ```typescript
736
+ * import { reset } from 'schemock/runtime';
737
+ *
738
+ * // Clear all mock data
739
+ * reset();
740
+ * ```
741
+ */
742
+ declare function reset(): void;
743
+ /**
744
+ * Seed with related data (maintains referential integrity).
745
+ *
746
+ * Seeds entities in dependency order, ensuring foreign keys
747
+ * reference valid parent entities.
748
+ *
749
+ * @param counts - Map of entity names to counts
750
+ * @param relations - Map of entity to foreign key relationships
751
+ *
752
+ * @example
753
+ * ```typescript
754
+ * import { seedWithRelations } from 'schemock/runtime';
755
+ *
756
+ * seedWithRelations(
757
+ * { user: 5, post: 20 },
758
+ * { post: { authorId: 'user' } }
759
+ * );
760
+ * ```
761
+ */
762
+ declare function seedWithRelations(counts: Record<string, number>, relations: Record<string, Record<string, string>>): void;
763
+
764
+ /**
765
+ * MSW Handlers Generator - REST handlers for all CRUD operations
766
+ *
767
+ * Generates MSW (Mock Service Worker) HTTP handlers from entity schemas,
768
+ * enabling automatic request interception for the MockAdapter.
769
+ *
770
+ * @module runtime/handlers
771
+ * @category Runtime
772
+ */
773
+
774
+ /**
775
+ * Handler options for customizing MSW behavior.
776
+ */
777
+ interface HandlerOptions {
778
+ /** Base URL for API endpoints */
779
+ baseUrl?: string;
780
+ /** Whether to log requests */
781
+ quiet?: boolean;
782
+ }
783
+ /**
784
+ * Create MSW REST handlers for all CRUD operations on entity schemas.
785
+ *
786
+ * Generates handlers for:
787
+ * - GET /{entity} - List all entities
788
+ * - GET /{entity}/:id - Get single entity
789
+ * - POST /{entity} - Create new entity
790
+ * - PUT /{entity}/:id - Update entity
791
+ * - PATCH /{entity}/:id - Partial update entity
792
+ * - DELETE /{entity}/:id - Delete entity
793
+ *
794
+ * @param schemas - Array of entity schemas to create handlers for
795
+ * @param adapter - The adapter to use for operations
796
+ * @param options - Handler configuration options
797
+ * @returns Array of MSW HTTP handlers
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * import { createHandlers } from 'schemock/runtime';
802
+ * import { setupWorker } from 'msw/browser';
803
+ *
804
+ * const handlers = createHandlers([userSchema, postSchema], mockAdapter, {
805
+ * baseUrl: '/api',
806
+ * });
807
+ *
808
+ * const worker = setupWorker(...handlers);
809
+ * await worker.start();
810
+ * ```
811
+ */
812
+ declare function createHandlers(schemas: EntitySchema[], adapter: Adapter, options?: HandlerOptions): HttpHandler[];
813
+
814
+ export { type CountOptions, type CreateInput, type Database, type EntityQueryOptions, type HandlerOptions, type ListQueryOptions, type ResolveRelationOptions, Resolver, type ResolverContext, SchemaRegistry, type SetupOptions, type UpdateInput, type ViewResolveOptions, ViewResolver, clearComputeCache, createHandlers, createResolver, createViewResolver, eagerLoadRelations, getAdapter, isInitialized, registry, reset, resolveComputedField, resolveComputedFields, resolveComputedFieldsSync, resolveRelation, resolveRelations, seed, seedWithRelations, setAdapter, setup, teardown, topologicalSort };