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 @@
1
+ {"version":3,"sources":["../../src/schema/types.ts","../../src/schema/field.ts","../../src/schema/relations.ts","../../src/schema/define-data.ts","../../src/schema/define-view.ts","../../src/schema/define-endpoint.ts"],"names":["field"],"mappings":";AAsQO,SAAS,gBAAgBA,MAAAA,EAAkD;AAChF,EAAA,OACE,OAAOA,WAAU,QAAA,IACjBA,MAAAA,KAAU,QACV,WAAA,IAAeA,MAAAA,IACdA,OAAkC,SAAA,KAAc,IAAA;AAErD;AAKO,SAAS,WAAWA,MAAAA,EAA6C;AACtE,EAAA,OACE,OAAOA,MAAAA,KAAU,QAAA,IACjBA,MAAAA,KAAU,QACV,MAAA,IAAUA,MAAAA,IACV,CAAC,SAAA,EAAW,WAAA,EAAa,QAAQ,CAAA,CAAE,QAAA,CAAUA,OAA6B,IAAI,CAAA;AAElF;AAqgBO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,WAAA,IAAe,KAAA,IACd,MAAyB,SAAA,KAAc,IAAA;AAE5C;;;ACtuBA,SAAS,kBAAqB,KAAA,EAAyC;AACrE,EAAA,MAAM,OAAA,GAA2B;AAAA,IAC/B,MAAM,KAAA,CAAM,IAAA;AAAA,IACZ,MAAM,KAAA,CAAM,IAAA;AAAA,IACZ,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,UAAU,KAAA,CAAM,QAAA;AAAA,IAChB,YAAY,KAAA,CAAM,UAAA;AAAA,IAClB,cAA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AA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACjD,IAAA,MAAA,CAAO,GAAG,CAAA,GAAI,cAAA,CAAe,KAAK,CAAA;AAAA,EACpC;AAEA,EAAA,OAAO,MAAA;AACT;AAqEO,SAAS,cAAA,CAKd,MACA,MAAA,EAC2C;AAE3C,EAAA,IAAI,CAAC,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,EAAG;AACzB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,mCAAA,EAAsC,IAAI,CAAA,CAAE,CAAA;AAAA,EAC9D;AAGA,EAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,MAAA,CAAO,MAAM,CAAA;AAC5C,EAAA,MAAM,IAAA,GAAO,eAAA,CAAgB,MAAA,CAAO,IAAI,CAAA;AACxC,EAAA,MAAM,QAAA,GAAW,eAAA,CAAgB,MAAA,CAAO,QAAQ,CAAA;AAGhD,EAAA,IAAI,MAAA,CAAO,KAAK,IAAI,CAAA,CAAE,SAAS,CAAA,IAAK,MAAA,CAAO,WAAW,KAAA,EAAO;AAC3D,IAAA,OAAA,CAAQ,IAAA,CAAK,CAAA,sFAAA,EAAyF,IAAI,CAAA,CAAE,CAAA;AAAA,EAC9G;AAEA,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,QAAQ,MAAA,CAAO,MAAA;AAAA,IACf,MAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,cAAc,MAAA,CAAO,YAAA;AAAA,IACrB,aAAa,MAAA,CAAO,WAAA;AAAA,IACpB,SAAA,EAAW;AAAA,GACb;AACF","file":"index.mjs","sourcesContent":["/**\n * Core type definitions for the Schemock Schema DSL\n *\n * @module schema/types\n * @category Schema\n */\n\n// ============================================================================\n// Field Types\n// ============================================================================\n\n/**\n * Constraint configuration for fields\n */\nexport interface FieldConstraints {\n /** Minimum value (for numbers) or minimum length (for strings/arrays) */\n min?: number;\n /** Maximum value (for numbers) or maximum length (for strings/arrays) */\n max?: number;\n /** Regular expression pattern for string validation */\n pattern?: RegExp;\n /** Custom validation message */\n message?: string;\n}\n\n/**\n * Base interface for all field definitions in the schema DSL.\n * Fields define the structure and behavior of entity properties.\n *\n * @example\n * ```typescript\n * const emailField: FieldDefinition<string> = {\n * type: 'email',\n * hint: 'internet.email',\n * nullable: false,\n * unique: true,\n * };\n * ```\n */\nexport interface FieldDefinition<T = unknown> {\n /** The primitive type of the field (string, number, boolean, date, array, object, ref) */\n type: string;\n /** Faker.js hint for generating mock data (e.g., 'person.fullName', 'internet.email') */\n hint?: string;\n /** Whether the field can be null */\n nullable?: boolean;\n /** Whether the field must be unique across all entities */\n unique?: boolean;\n /** Whether the field is read-only (excluded from create/update operations) */\n readOnly?: boolean;\n /** Default value when not provided */\n default?: T;\n /** Validation constraints */\n constraints?: FieldConstraints;\n /** For array fields: the type of items */\n items?: FieldDefinition;\n /** For object fields: the shape of nested properties */\n shape?: Record<string, FieldDefinition>;\n /** For ref fields: the target entity name */\n target?: string;\n /** For enum fields: the allowed values */\n values?: readonly T[];\n /** Internal type marker for TypeScript inference */\n readonly _type?: T;\n}\n\n/**\n * Builder interface for creating field definitions with chainable methods.\n * All field builder methods return a new builder instance to support method chaining.\n *\n * @example\n * ```typescript\n * const field = createFieldBuilder('string')\n * .min(1)\n * .max(100)\n * .nullable()\n * .default('');\n * ```\n */\nexport interface FieldBuilder<T> {\n /** The primitive type of the field */\n type: string;\n /** Faker.js hint for generating mock data */\n hint?: string;\n /** Whether the field can be null - use nullable() method to set */\n isNullable?: boolean;\n /** Whether the field must be unique */\n isUnique?: boolean;\n /** Whether the field is read-only */\n isReadOnly?: boolean;\n /** Default value */\n defaultValue?: T;\n /** Validation constraints */\n constraints?: FieldConstraints;\n /** For array fields */\n items?: FieldDefinition;\n /** For object fields */\n shape?: Record<string, FieldDefinition>;\n /** For ref fields */\n target?: string;\n /** For enum fields */\n values?: readonly T[];\n /** Internal type marker */\n readonly _type?: T;\n\n /** Mark the field as nullable */\n nullable(): FieldBuilder<T | null>;\n /** Mark the field as unique */\n unique(message?: string): FieldBuilder<T>;\n /** Mark the field as read-only */\n readOnly(): FieldBuilder<T>;\n /** Set a default value */\n default(value: T): FieldBuilder<T>;\n /** Set minimum constraint */\n min(value: number, message?: string): FieldBuilder<T>;\n /** Set maximum constraint */\n max(value: number, message?: string): FieldBuilder<T>;\n /** Set regex pattern constraint */\n pattern(regex: RegExp, message?: string): FieldBuilder<T>;\n}\n\n/**\n * Extended builder for string fields with additional string-specific options\n */\nexport interface StringFieldBuilder extends FieldBuilder<string> {\n /** Set minimum length */\n min(length: number, message?: string): StringFieldBuilder;\n /** Set maximum length */\n max(length: number, message?: string): StringFieldBuilder;\n /** Set regex pattern */\n pattern(regex: RegExp, message?: string): StringFieldBuilder;\n}\n\n/**\n * Extended builder for number fields with numeric-specific options\n */\nexport interface NumberFieldBuilder extends FieldBuilder<number> {\n /** Set minimum value */\n min(value: number, message?: string): NumberFieldBuilder;\n /** Set maximum value */\n max(value: number, message?: string): NumberFieldBuilder;\n /** Constrain to integer values */\n int(): NumberFieldBuilder;\n}\n\n/**\n * Extended builder for date fields with date-specific options\n */\nexport interface DateFieldBuilder extends FieldBuilder<Date> {\n /** Constrain to past dates */\n past(): DateFieldBuilder;\n /** Constrain to future dates */\n future(): DateFieldBuilder;\n /** Constrain to recent dates */\n recent(): DateFieldBuilder;\n /** Constrain between specific dates */\n between(options: { from: string | Date; to: string | Date }): DateFieldBuilder;\n}\n\n/**\n * Extended builder for enum fields with type-safe values\n */\nexport interface EnumFieldBuilder<T extends string> extends FieldBuilder<T> {\n /** Set default enum value */\n default(value: T): EnumFieldBuilder<T>;\n}\n\n/**\n * Extended builder for reference fields pointing to other entities\n */\nexport interface RefFieldBuilder extends FieldBuilder<string> {\n /** The target entity name */\n readonly target: string;\n}\n\n/**\n * Extended builder for array fields\n */\nexport interface ArrayFieldBuilder<T> extends FieldBuilder<T[]> {\n /** Set minimum array length */\n min(length: number): ArrayFieldBuilder<T>;\n /** Set maximum array length */\n max(length: number): ArrayFieldBuilder<T>;\n /** Set exact array length */\n length(count: number): ArrayFieldBuilder<T>;\n}\n\n/**\n * Extended builder for object fields with nested shape\n */\nexport interface ObjectFieldBuilder<T> extends FieldBuilder<T> {\n /** The shape definition of nested properties */\n readonly shape: Record<string, FieldDefinition>;\n}\n\n// ============================================================================\n// Relation Types\n// ============================================================================\n\n/**\n * Defines a relationship between entities.\n * Supports one-to-one, one-to-many, and many-to-many relationships.\n *\n * @example\n * ```typescript\n * const userPostsRelation: RelationDefinition = {\n * type: 'hasMany',\n * target: 'post',\n * foreignKey: 'authorId',\n * orderBy: { createdAt: 'desc' },\n * };\n * ```\n */\nexport interface RelationDefinition {\n /** The type of relationship */\n type: 'hasMany' | 'belongsTo' | 'hasOne';\n /** The target entity name */\n target: string;\n /** The foreign key field name (on the related entity for hasMany/hasOne, on this entity for belongsTo) */\n foreignKey?: string;\n /** Whether to eagerly load the relation by default */\n eager?: boolean;\n /** Default ordering for hasMany relations */\n orderBy?: Record<string, 'asc' | 'desc'>;\n /** Default limit for hasMany relations */\n limit?: number;\n /** For many-to-many: the junction table name */\n through?: string;\n /** For many-to-many: the other foreign key on the junction table */\n otherKey?: string;\n}\n\n// ============================================================================\n// Computed Field Types\n// ============================================================================\n\n/**\n * Configuration for computed fields that derive their value from other data.\n *\n * @example\n * ```typescript\n * const fullNameComputed: ComputedFieldDefinition<string> = {\n * resolve: (entity) => `${entity.firstName} ${entity.lastName}`,\n * dependsOn: ['firstName', 'lastName'],\n * };\n * ```\n */\nexport interface ComputedFieldDefinition<T = unknown> {\n /** Function to generate mock data for this computed field */\n mock?: () => T;\n /** Function to resolve the actual value from entity data */\n resolve: (entity: Record<string, unknown>, db: unknown, ctx: unknown) => T | Promise<T>;\n /** Fields this computed field depends on (for ordering resolution) */\n dependsOn?: string[];\n /** Internal type marker */\n readonly _computed: true;\n readonly _type?: T;\n}\n\n/**\n * Type guard to check if a field definition is a computed field\n */\nexport function isComputedField(field: unknown): field is ComputedFieldDefinition {\n return (\n typeof field === 'object' &&\n field !== null &&\n '_computed' in field &&\n (field as ComputedFieldDefinition)._computed === true\n );\n}\n\n/**\n * Type guard to check if a field definition is a relation\n */\nexport function isRelation(field: unknown): field is RelationDefinition {\n return (\n typeof field === 'object' &&\n field !== null &&\n 'type' in field &&\n ['hasMany', 'belongsTo', 'hasOne'].includes((field as RelationDefinition).type)\n );\n}\n\n// ============================================================================\n// Entity Schema Types\n// ============================================================================\n\n/**\n * API configuration for an entity\n */\nexport interface EntityApiConfig {\n /** Base path for REST endpoints (e.g., '/api/users') */\n basePath: string;\n /** Enable/disable specific CRUD operations */\n operations?: {\n list?: boolean;\n get?: boolean;\n create?: boolean;\n update?: boolean;\n delete?: boolean;\n [key: string]: boolean | { method: string; path: string; params?: string[] } | undefined;\n };\n /** Pagination configuration */\n pagination?: {\n style: 'offset' | 'cursor';\n defaultLimit?: number;\n maxLimit?: number;\n };\n /** Relationship endpoint configuration */\n relationships?: Record<\n string,\n {\n endpoint?: boolean;\n operations?: Array<'list' | 'create' | 'update' | 'delete'>;\n }\n >;\n}\n\n// ============================================================================\n// Index Configuration Types\n// ============================================================================\n\n/**\n * Index configuration for database optimization.\n *\n * @example Simple index\n * ```typescript\n * { fields: ['authorId'] }\n * ```\n *\n * @example Composite unique index\n * ```typescript\n * { fields: ['email', 'tenantId'], unique: true }\n * ```\n *\n * @example Full-text search index\n * ```typescript\n * {\n * fields: ['title'],\n * type: 'gin',\n * using: \"to_tsvector('english', title)\",\n * }\n * ```\n *\n * @example Partial index\n * ```typescript\n * {\n * fields: ['createdAt'],\n * where: \"status = 'active'\",\n * }\n * ```\n */\nexport interface IndexConfig {\n /** Column names to index */\n fields: string[];\n /** Custom index name (auto-generated if not provided) */\n name?: string;\n /** Index type (default: btree) */\n type?: 'btree' | 'hash' | 'gin' | 'gist' | 'brin';\n /** Custom expression for functional indexes (e.g., \"to_tsvector('english', title)\") */\n using?: string;\n /** Create unique index */\n unique?: boolean;\n /** Partial index condition (WHERE clause) */\n where?: string;\n /** Use CONCURRENTLY for production migrations (avoids locking) */\n concurrently?: boolean;\n}\n\n// ============================================================================\n// RPC/Stored Procedure Configuration Types\n// ============================================================================\n\n/**\n * RPC/Stored procedure argument definition.\n *\n * @example\n * ```typescript\n * { name: 'user_id', type: 'uuid' }\n * { name: 'limit', type: 'integer', default: '20' }\n * ```\n */\nexport interface RPCArgument {\n /** Argument name */\n name: string;\n /** PostgreSQL type (uuid, text, integer, boolean, jsonb, etc.) */\n type: string;\n /** Default value as SQL expression (optional) */\n default?: string;\n}\n\n/**\n * RPC/Stored procedure configuration.\n *\n * @example Simple query function\n * ```typescript\n * {\n * args: [{ name: 'user_id', type: 'uuid' }],\n * returns: 'post[]',\n * sql: \"SELECT * FROM posts WHERE author_id = $1\",\n * volatility: 'stable',\n * }\n * ```\n *\n * @example Mutation function\n * ```typescript\n * {\n * args: [{ name: 'post_id', type: 'uuid' }],\n * returns: 'post',\n * sql: \"UPDATE posts SET status = 'published' WHERE id = $1 RETURNING *\",\n * volatility: 'volatile',\n * }\n * ```\n *\n * @example PL/pgSQL function\n * ```typescript\n * {\n * args: [{ name: 'user_id', type: 'uuid' }],\n * returns: 'integer',\n * language: 'plpgsql',\n * sql: `\n * DECLARE\n * v_count integer;\n * BEGIN\n * SELECT COUNT(*) INTO v_count FROM posts WHERE author_id = user_id;\n * RETURN v_count;\n * END;\n * `,\n * }\n * ```\n */\nexport interface RPCConfig {\n /** Function arguments */\n args?: RPCArgument[];\n /** Return type: 'void', entity name (e.g., 'post'), array (e.g., 'post[]'), or PostgreSQL type */\n returns: string;\n /** SQL function body */\n sql: string;\n /** Function language (default: sql) */\n language?: 'sql' | 'plpgsql';\n /** Volatility marker for query optimization (default: volatile) */\n volatility?: 'volatile' | 'stable' | 'immutable';\n /** Security context (default: invoker) */\n security?: 'invoker' | 'definer';\n /** Function description for documentation */\n description?: string;\n}\n\n// ============================================================================\n// Entity Options\n// ============================================================================\n\n/**\n * Options for entity schema configuration\n */\nexport interface EntityOptions<T = unknown> {\n /** API endpoint configuration */\n api?: EntityApiConfig;\n /** Whether to automatically add timestamp fields (createdAt, updatedAt) */\n timestamps?: boolean;\n /** Row-level security configuration */\n rls?: RLSConfig<T>;\n /** Database indexes for query optimization */\n indexes?: IndexConfig[];\n /** RPC/Stored procedures related to this entity */\n rpc?: Record<string, RPCConfig>;\n}\n\n/**\n * Complete schema definition for an entity.\n * This is the primary output of the defineData function.\n *\n * @example\n * ```typescript\n * const userSchema: EntitySchema = {\n * name: 'user',\n * fields: { id: field.uuid(), name: field.string() },\n * relations: { posts: hasMany('post') },\n * computed: { postCount: field.computed({...}) },\n * };\n * ```\n */\n/**\n * Generic context for RLS evaluation.\n * Can represent users, API keys, services, tenants, or any other context.\n *\n * @example\n * ```typescript\n * // User-based context\n * const userCtx: RLSContext = { userId: 'user-123', role: 'admin', orgId: 'org-456' };\n *\n * // API key context (no user)\n * const apiKeyCtx: RLSContext = { tenantId: 'tenant-789', scope: 'read' };\n *\n * // Service-to-service context\n * const serviceCtx: RLSContext = { serviceId: 'payment-service', environment: 'prod' };\n * ```\n */\nexport interface RLSContext {\n [key: string]: unknown;\n}\n\n/**\n * Row-level security policy filter function.\n * Receives the row data and current context (can be null if no context set).\n */\nexport type RLSFilter<T = unknown> = (row: T, context: RLSContext | null) => boolean;\n\n/**\n * Scope mapping: maps a row field to a context key.\n * Used for automatic policy generation.\n *\n * @example\n * ```typescript\n * // Row field 'authorId' must match context key 'userId'\n * { field: 'authorId', contextKey: 'userId' }\n *\n * // Row field 'tenantId' must match context key 'tenantId'\n * { field: 'tenantId', contextKey: 'tenantId' }\n * ```\n */\nexport interface RLSScopeMapping {\n /** The field name on the row/entity */\n field: string;\n /** The key in the RLS context to compare against */\n contextKey: string;\n}\n\n/**\n * Bypass condition for RLS.\n * When the context matches this condition, RLS is bypassed.\n */\nexport interface RLSBypass {\n /** Context key to check */\n contextKey: string;\n /** Values that trigger bypass (e.g., ['admin', 'superuser']) */\n values: string[];\n}\n\n/**\n * Row-level security configuration for an entity.\n * Works with any context - users, API keys, services, tenants, etc.\n *\n * @example Simple scope-based (works without users)\n * ```typescript\n * const Post = defineData('post', { ... }, {\n * rls: {\n * // Rows filtered by tenantId from context\n * scope: [{ field: 'tenantId', contextKey: 'tenantId' }],\n * },\n * });\n * ```\n *\n * @example User-based with owner field\n * ```typescript\n * const Post = defineData('post', { ... }, {\n * rls: {\n * scope: [{ field: 'authorId', contextKey: 'userId' }],\n * bypass: [{ contextKey: 'role', values: ['admin'] }],\n * },\n * });\n * ```\n *\n * @example Custom filter functions\n * ```typescript\n * const Post = defineData('post', { ... }, {\n * rls: {\n * select: (row, ctx) => row.isPublic || row.authorId === ctx?.userId,\n * insert: (row, ctx) => row.authorId === ctx?.userId,\n * },\n * });\n * ```\n */\nexport interface RLSConfig<T = unknown> {\n /**\n * Scope mappings for automatic policy generation.\n * Each mapping requires row[field] === context[contextKey].\n */\n scope?: RLSScopeMapping[];\n\n /**\n * Conditions that bypass RLS entirely.\n * If any bypass condition matches, all operations are allowed.\n */\n bypass?: RLSBypass[];\n\n /** Custom filter for SELECT/read operations */\n select?: RLSFilter<T>;\n /** Custom filter for INSERT operations */\n insert?: RLSFilter<T>;\n /** Custom filter for UPDATE operations */\n update?: RLSFilter<T>;\n /** Custom filter for DELETE operations */\n delete?: RLSFilter<T>;\n\n /**\n * PostgreSQL-compatible policy SQL for PGlite/Supabase.\n * Use current_setting('app.{contextKey}') to reference context values.\n */\n sql?: {\n select?: string;\n insert?: string;\n update?: string;\n delete?: string;\n };\n}\n\nexport interface EntitySchema<T = unknown> {\n /** The unique name of this entity */\n name: string;\n /** Field definitions */\n fields: Record<string, FieldDefinition>;\n /** Relation definitions */\n relations?: Record<string, RelationDefinition>;\n /** Computed field definitions */\n computed?: Record<string, ComputedFieldDefinition>;\n /** Whether to include timestamp fields */\n timestamps?: boolean;\n /** API configuration */\n api?: EntityApiConfig;\n /** Row-level security configuration */\n rls?: RLSConfig<T>;\n /** Database indexes for query optimization */\n indexes?: IndexConfig[];\n /** RPC/Stored procedures related to this entity */\n rpc?: Record<string, RPCConfig>;\n /** Internal type marker */\n readonly _entity?: T;\n}\n\n// ============================================================================\n// View Schema Types\n// ============================================================================\n\n/**\n * Embed configuration for including related data in views\n */\nexport interface EmbedConfig {\n /** Maximum number of items to include */\n limit?: number;\n /** Ordering for embedded items */\n orderBy?: Record<string, 'asc' | 'desc'>;\n /** Fields to include (defaults to all) */\n select?: string[];\n}\n\n/**\n * View field value type - supports fields, computed, embeds, and nested objects\n */\nexport type ViewFieldValue =\n | FieldDefinition\n | ComputedFieldDefinition\n | { _embed: true; entity: EntitySchema; config?: EmbedConfig }\n | Record<string, FieldDefinition | ComputedFieldDefinition>;\n\n/**\n * View field definitions (subset of entity fields + embedded relations)\n */\nexport type ViewFields = Record<string, ViewFieldValue>;\n\n/**\n * Options for view schema configuration\n */\nexport interface ViewOptions {\n /** The API endpoint for this view */\n endpoint: string;\n /** URL parameters required for this view */\n params: string[];\n}\n\n/**\n * Schema definition for a computed view over entities.\n *\n * @example\n * ```typescript\n * const userFullView: ViewSchema = {\n * name: 'user-full',\n * fields: { id: field.uuid(), name: field.string() },\n * endpoint: '/api/users/:id/full',\n * params: ['id'],\n * };\n * ```\n */\nexport interface ViewSchema {\n /** The unique name of this view */\n name: string;\n /** Field definitions for the view output */\n fields: ViewFields;\n /** The API endpoint */\n endpoint: string;\n /** Required URL parameters */\n params: string[];\n}\n\n// ============================================================================\n// Custom Endpoint Types\n// ============================================================================\n\n/**\n * HTTP methods supported for custom endpoints\n */\nexport type EndpointMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/**\n * Context passed to mock resolver functions.\n * Provides access to request data and the mock database.\n *\n * @example\n * ```typescript\n * mockResolver: async ({ params, body, db }) => {\n * const users = db.user.findMany({ where: { name: { contains: params.q } } });\n * return { results: users, total: users.length };\n * }\n * ```\n */\nexport interface MockResolverContext<TParams = Record<string, unknown>, TBody = Record<string, unknown>> {\n /** Parsed query/path parameters */\n params: TParams;\n /** Parsed request body (for POST/PUT/PATCH) */\n body: TBody;\n /** Access to mock database */\n db: unknown;\n /** Request headers */\n headers: Record<string, string>;\n}\n\n/**\n * Configuration for defining a custom endpoint.\n *\n * @example\n * ```typescript\n * const config: EndpointConfig = {\n * method: 'GET',\n * params: { q: field.string(), limit: field.number.int().default(20) },\n * response: { results: field.array(field.object({...})), total: field.number.int() },\n * mockResolver: async ({ params, db }) => ({ results: [], total: 0 }),\n * };\n * ```\n */\nexport interface EndpointConfig<\n TParams = Record<string, unknown>,\n TBody = Record<string, unknown>,\n TResponse = unknown,\n> {\n /** HTTP method */\n method: EndpointMethod;\n /** Query/path parameter definitions */\n params?: Record<string, FieldBuilder<unknown> | FieldDefinition>;\n /** Request body definition (for POST/PUT/PATCH) */\n body?: Record<string, FieldBuilder<unknown> | FieldDefinition>;\n /** Response schema definition */\n response: Record<string, FieldBuilder<unknown> | FieldDefinition>;\n /** Mock resolver function that generates fake responses */\n mockResolver: (ctx: MockResolverContext<TParams, TBody>) => TResponse | Promise<TResponse>;\n /** Optional description for documentation */\n description?: string;\n}\n\n/**\n * Complete endpoint schema definition.\n * This is the output of the defineEndpoint function.\n *\n * @example\n * ```typescript\n * const SearchEndpoint = defineEndpoint('/api/search', {\n * method: 'GET',\n * params: { q: field.string() },\n * response: { results: field.array(field.string()) },\n * mockResolver: async ({ params, db }) => ({ results: [] }),\n * });\n * ```\n */\nexport interface EndpointSchema<\n TParams = Record<string, unknown>,\n TBody = Record<string, unknown>,\n TResponse = unknown,\n> {\n /** Endpoint path (e.g., '/api/search', '/api/orders/:id') */\n path: string;\n /** HTTP method */\n method: EndpointMethod;\n /** Parameter definitions (normalized to FieldDefinition) */\n params: Record<string, FieldDefinition>;\n /** Body definitions (normalized to FieldDefinition) */\n body: Record<string, FieldDefinition>;\n /** Response definitions (normalized to FieldDefinition) */\n response: Record<string, FieldDefinition>;\n /** Mock resolver function */\n mockResolver: (ctx: MockResolverContext<TParams, TBody>) => TResponse | Promise<TResponse>;\n /** Description for documentation */\n description?: string;\n /** Internal marker for type identification */\n readonly _endpoint: true;\n}\n\n/**\n * Type guard to check if a value is an EndpointSchema\n */\nexport function isEndpointSchema(value: unknown): value is EndpointSchema {\n return (\n typeof value === 'object' &&\n value !== null &&\n '_endpoint' in value &&\n (value as EndpointSchema)._endpoint === true\n );\n}\n\n// ============================================================================\n// Type Inference Utilities\n// ============================================================================\n\n/**\n * Maps field types to their TypeScript equivalents\n */\ntype FieldTypeMap = {\n string: string;\n uuid: string;\n email: string;\n url: string;\n number: number;\n int: number;\n float: number;\n boolean: boolean;\n date: Date;\n array: unknown[];\n object: Record<string, unknown>;\n ref: string;\n enum: string;\n};\n\n/**\n * Infer the TypeScript type from a FieldDefinition\n */\nexport type InferFieldType<F extends FieldDefinition> = F['nullable'] extends true\n ? (F extends { _type: infer T } ? T : FieldTypeMap[F['type'] & keyof FieldTypeMap]) | null\n : F extends { _type: infer T }\n ? T\n : FieldTypeMap[F['type'] & keyof FieldTypeMap];\n\n/**\n * Infer the complete entity type from an EntitySchema\n *\n * @example\n * ```typescript\n * const User = defineData('user', { id: field.uuid(), name: field.string() });\n * type UserType = InferEntity<typeof User>;\n * // { id: string; name: string; }\n * ```\n */\nexport type InferEntity<S extends EntitySchema> = {\n [K in keyof S['fields']]: InferFieldType<S['fields'][K]>;\n} & (S['relations'] extends Record<string, RelationDefinition>\n ? {\n [K in keyof S['relations']]?: S['relations'][K]['type'] extends 'hasMany' ? unknown[] : unknown;\n }\n : object) &\n (S['computed'] extends Record<string, ComputedFieldDefinition>\n ? { [K in keyof S['computed']]: S['computed'][K]['_type'] }\n : object);\n\n/**\n * Infer the type for creating a new entity (excludes id, readOnly, computed fields)\n *\n * @example\n * ```typescript\n * type UserCreate = InferCreate<typeof User>;\n * // { name: string; email: string; } (without id, createdAt, etc.)\n * ```\n */\nexport type InferCreate<S extends EntitySchema> = {\n [K in keyof S['fields'] as S['fields'][K]['readOnly'] extends true\n ? never\n : K extends 'id'\n ? never\n : K]: S['fields'][K]['default'] extends undefined\n ? InferFieldType<S['fields'][K]>\n : InferFieldType<S['fields'][K]> | undefined;\n};\n\n/**\n * Infer the type for updating an entity (all fields optional, excludes readOnly)\n *\n * @example\n * ```typescript\n * type UserUpdate = InferUpdate<typeof User>;\n * // { name?: string; email?: string; }\n * ```\n */\nexport type InferUpdate<S extends EntitySchema> = Partial<InferCreate<S>>;\n","/**\n * Field builder functions for the Schemock Schema DSL.\n * Provides a fluent API for defining entity fields with type-specific defaults\n * and chainable modifiers.\n *\n * @module schema/field\n * @category Schema\n *\n * @example\n * ```typescript\n * import { field } from 'schemock/schema';\n *\n * const User = defineData('user', {\n * id: field.uuid(),\n * name: field.string({ hint: 'person.fullName' }),\n * email: field.email().unique(),\n * age: field.number({ min: 0, max: 150 }).nullable(),\n * role: field.enum(['admin', 'user']).default('user'),\n * createdAt: field.date().readOnly(),\n * });\n * ```\n */\n\nimport type {\n FieldDefinition,\n FieldBuilder,\n StringFieldBuilder,\n NumberFieldBuilder,\n DateFieldBuilder,\n EnumFieldBuilder,\n RefFieldBuilder,\n ArrayFieldBuilder,\n ObjectFieldBuilder,\n ComputedFieldDefinition,\n FieldConstraints,\n} from './types';\n\n// ============================================================================\n// Internal Builder Factory\n// ============================================================================\n\n/**\n * Internal state for field builder\n * @internal\n */\ninterface BuilderState<T> {\n type: string;\n hint?: string;\n isNullable?: boolean;\n isUnique?: boolean;\n isReadOnly?: boolean;\n defaultValue?: T;\n constraints?: FieldConstraints;\n items?: FieldDefinition;\n shape?: Record<string, FieldDefinition>;\n target?: string;\n values?: readonly T[];\n}\n\n/**\n * Creates a base field builder with chainable methods\n * @internal\n */\nfunction createBaseBuilder<T>(state: BuilderState<T>): FieldBuilder<T> {\n const builder: FieldBuilder<T> = {\n type: state.type,\n hint: state.hint,\n isNullable: state.isNullable,\n isUnique: state.isUnique,\n isReadOnly: state.isReadOnly,\n defaultValue: state.defaultValue,\n constraints: state.constraints,\n items: state.items,\n shape: state.shape,\n target: state.target,\n values: state.values,\n\n nullable(): FieldBuilder<T | null> {\n return createBaseBuilder<T | null>({ ...state, isNullable: true });\n },\n\n unique(message?: string): FieldBuilder<T> {\n return createBaseBuilder<T>({\n ...state,\n isUnique: true,\n constraints: { ...state.constraints, message: message || state.constraints?.message },\n });\n },\n\n readOnly(): FieldBuilder<T> {\n return createBaseBuilder<T>({ ...state, isReadOnly: true });\n },\n\n default(value: T): FieldBuilder<T> {\n return createBaseBuilder<T>({ ...state, defaultValue: value });\n },\n\n min(value: number, message?: string): FieldBuilder<T> {\n return createBaseBuilder<T>({\n ...state,\n constraints: { ...state.constraints, min: value, message: message || state.constraints?.message },\n });\n },\n\n max(value: number, message?: string): FieldBuilder<T> {\n return createBaseBuilder<T>({\n ...state,\n constraints: { ...state.constraints, max: value, message: message || state.constraints?.message },\n });\n },\n\n pattern(regex: RegExp, message?: string): FieldBuilder<T> {\n return createBaseBuilder<T>({\n ...state,\n constraints: { ...state.constraints, pattern: regex, message: message || state.constraints?.message },\n });\n },\n };\n\n return builder;\n}\n\n/**\n * Creates a string field builder with string-specific methods\n * @internal\n */\nfunction createStringBuilder(state: BuilderState<string>): StringFieldBuilder {\n const base = createBaseBuilder<string>(state);\n return {\n ...base,\n min(length: number, message?: string): StringFieldBuilder {\n return createStringBuilder({\n ...state,\n constraints: { ...state.constraints, min: length, message: message || state.constraints?.message },\n });\n },\n max(length: number, message?: string): StringFieldBuilder {\n return createStringBuilder({\n ...state,\n constraints: { ...state.constraints, max: length, message: message || state.constraints?.message },\n });\n },\n pattern(regex: RegExp, message?: string): StringFieldBuilder {\n return createStringBuilder({\n ...state,\n constraints: { ...state.constraints, pattern: regex, message: message || state.constraints?.message },\n });\n },\n } as StringFieldBuilder;\n}\n\n/**\n * Creates a number field builder with numeric-specific methods\n * @internal\n */\nfunction createNumberBuilder(state: BuilderState<number>): NumberFieldBuilder {\n const base = createBaseBuilder<number>(state);\n return {\n ...base,\n min(value: number, message?: string): NumberFieldBuilder {\n return createNumberBuilder({\n ...state,\n constraints: { ...state.constraints, min: value, message: message || state.constraints?.message },\n });\n },\n max(value: number, message?: string): NumberFieldBuilder {\n return createNumberBuilder({\n ...state,\n constraints: { ...state.constraints, max: value, message: message || state.constraints?.message },\n });\n },\n int(): NumberFieldBuilder {\n return createNumberBuilder({ ...state, hint: 'number.int' });\n },\n } as NumberFieldBuilder;\n}\n\n/**\n * Creates a date field builder with date-specific methods\n * @internal\n */\nfunction createDateBuilder(state: BuilderState<Date>): DateFieldBuilder {\n const base = createBaseBuilder<Date>(state);\n return {\n ...base,\n past(): DateFieldBuilder {\n return createDateBuilder({ ...state, hint: 'date.past' });\n },\n future(): DateFieldBuilder {\n return createDateBuilder({ ...state, hint: 'date.future' });\n },\n recent(): DateFieldBuilder {\n return createDateBuilder({ ...state, hint: 'date.recent' });\n },\n between(options: { from: string | Date; to: string | Date }): DateFieldBuilder {\n return createDateBuilder({\n ...state,\n hint: 'date.between',\n constraints: {\n ...state.constraints,\n // Store date range in constraints for MockAdapter to use\n min: new Date(options.from).getTime(),\n max: new Date(options.to).getTime(),\n },\n });\n },\n } as DateFieldBuilder;\n}\n\n/**\n * Creates an enum field builder with type-safe values\n * @internal\n */\nfunction createEnumBuilder<T extends string>(values: readonly T[], defaultVal?: T): EnumFieldBuilder<T> {\n const state: BuilderState<T> = {\n type: 'enum',\n values,\n hint: 'helpers.arrayElement',\n defaultValue: defaultVal,\n };\n const base = createBaseBuilder<T>(state);\n return {\n ...base,\n default(value: T): EnumFieldBuilder<T> {\n return createEnumBuilder(values, value);\n },\n } as EnumFieldBuilder<T>;\n}\n\n/**\n * Creates a reference field builder\n * @internal\n */\nfunction createRefBuilder(target: string): RefFieldBuilder {\n const state: BuilderState<string> = {\n type: 'ref',\n target,\n hint: 'string.uuid',\n };\n return {\n ...createBaseBuilder<string>(state),\n target,\n } as RefFieldBuilder;\n}\n\n/**\n * Creates an array field builder\n * @internal\n */\nfunction createArrayBuilder<T>(itemType: FieldDefinition<T>, constraints?: FieldConstraints): ArrayFieldBuilder<T> {\n const state: BuilderState<T[]> = {\n type: 'array',\n items: itemType,\n hint: 'array',\n constraints,\n };\n const base = createBaseBuilder<T[]>(state);\n return {\n ...base,\n min(length: number): ArrayFieldBuilder<T> {\n return createArrayBuilder(itemType, { ...constraints, min: length });\n },\n max(length: number): ArrayFieldBuilder<T> {\n return createArrayBuilder(itemType, { ...constraints, max: length });\n },\n length(count: number): ArrayFieldBuilder<T> {\n return createArrayBuilder(itemType, { ...constraints, min: count, max: count });\n },\n } as ArrayFieldBuilder<T>;\n}\n\n/**\n * Creates an object field builder with nested shape\n * @internal\n */\nfunction createObjectBuilder<T extends Record<string, unknown>>(shape: Record<string, FieldDefinition>): ObjectFieldBuilder<T> {\n const state: BuilderState<T> = {\n type: 'object',\n shape,\n hint: 'object',\n };\n return {\n ...createBaseBuilder<T>(state),\n shape,\n } as ObjectFieldBuilder<T>;\n}\n\n// ============================================================================\n// Computed Field Factory\n// ============================================================================\n\n/**\n * Creates a computed field definition\n *\n * @param config - Computed field configuration\n * @returns ComputedFieldDefinition\n *\n * @example\n * ```typescript\n * const fullName = field.computed({\n * resolve: (entity) => `${entity.firstName} ${entity.lastName}`,\n * dependsOn: ['firstName', 'lastName'],\n * });\n * ```\n */\nfunction createComputedField<T>(config: {\n mock?: () => T;\n resolve: (entity: Record<string, unknown>, db: unknown, ctx: unknown) => T | Promise<T>;\n dependsOn?: string[];\n}): ComputedFieldDefinition<T> {\n return {\n ...config,\n _computed: true as const,\n };\n}\n\n// ============================================================================\n// Field Builder API\n// ============================================================================\n\n/**\n * Fluent builder API for defining entity fields with type-specific defaults\n * and chainable modifiers.\n *\n * @example\n * ```typescript\n * // Basic types\n * field.uuid() // UUID v4 string\n * field.string() // Random string\n * field.number() // Random number\n * field.boolean() // Random boolean\n * field.date() // Random date\n *\n * // With constraints\n * field.string().min(1).max(100) // Constrained string\n * field.number({ min: 0, max: 100 }) // Bounded number\n *\n * // With modifiers\n * field.string().nullable() // Can be null\n * field.email().unique() // Must be unique\n * field.date().readOnly() // Excluded from create/update\n *\n * // Complex types\n * field.enum(['a', 'b', 'c']) // One of values\n * field.ref('user') // Reference to entity\n * field.array(field.string()) // Array of strings\n * field.object({ name: field.string() }) // Nested object\n *\n * // Computed fields\n * field.computed({\n * resolve: (entity) => entity.firstName + entity.lastName,\n * dependsOn: ['firstName', 'lastName'],\n * })\n * ```\n */\nexport const field = {\n // -------------------------------------------------------------------------\n // Primitive Types\n // -------------------------------------------------------------------------\n\n /**\n * UUID v4 string field\n * @returns FieldBuilder<string>\n */\n uuid(): FieldBuilder<string> {\n return createBaseBuilder<string>({ type: 'uuid', hint: 'string.uuid' });\n },\n\n /**\n * String field with optional hint for mock data generation\n * @param opts - Options including faker hint\n */\n string(opts?: { hint?: string }): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: opts?.hint || 'lorem.word' });\n },\n\n /**\n * Number field with optional constraints\n * @param opts - Min, max, and integer constraints\n */\n number(opts?: { min?: number; max?: number; int?: boolean }): NumberFieldBuilder {\n const constraints: FieldConstraints = {};\n if (opts?.min !== undefined) constraints.min = opts.min;\n if (opts?.max !== undefined) constraints.max = opts.max;\n\n return createNumberBuilder({\n type: 'number',\n hint: opts?.int ? 'number.int' : 'number.float',\n constraints: Object.keys(constraints).length > 0 ? constraints : undefined,\n });\n },\n\n /**\n * Boolean field\n */\n boolean(): FieldBuilder<boolean> {\n return createBaseBuilder<boolean>({ type: 'boolean', hint: 'datatype.boolean' });\n },\n\n /**\n * Date field with optional constraints\n * @param opts - Past/future constraints\n */\n date(opts?: { past?: boolean; future?: boolean }): DateFieldBuilder {\n let hint = 'date.anytime';\n if (opts?.past) hint = 'date.past';\n if (opts?.future) hint = 'date.future';\n\n return createDateBuilder({ type: 'date', hint });\n },\n\n // -------------------------------------------------------------------------\n // Semantic Types (Faker-based)\n // -------------------------------------------------------------------------\n\n /**\n * Email string field\n */\n email(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.email' });\n },\n\n /**\n * URL string field\n */\n url(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.url' });\n },\n\n // -------------------------------------------------------------------------\n // Faker Namespace Proxies\n // -------------------------------------------------------------------------\n\n /**\n * Person-related fields (names, titles, etc.)\n */\n person: {\n fullName(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'person.fullName' });\n },\n firstName(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'person.firstName' });\n },\n lastName(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'person.lastName' });\n },\n bio(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'person.bio' });\n },\n jobTitle(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'person.jobTitle' });\n },\n },\n\n /**\n * Internet-related fields (emails, URLs, usernames, etc.)\n */\n internet: {\n email(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.email' });\n },\n url(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.url' });\n },\n avatar(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.avatar' });\n },\n userName(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.userName' });\n },\n password(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'internet.password' });\n },\n },\n\n /**\n * Lorem ipsum text generation\n */\n lorem: {\n word(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'lorem.word' });\n },\n sentence(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'lorem.sentence' });\n },\n paragraph(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'lorem.paragraph' });\n },\n paragraphs(count: number = 3): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: `lorem.paragraphs:${count}` });\n },\n },\n\n /**\n * Location-related fields (addresses, cities, etc.)\n */\n location: {\n city(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'location.city' });\n },\n country(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'location.country' });\n },\n streetAddress(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'location.streetAddress' });\n },\n zipCode(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'location.zipCode' });\n },\n latitude(): NumberFieldBuilder {\n return createNumberBuilder({ type: 'number', hint: 'location.latitude' });\n },\n longitude(): NumberFieldBuilder {\n return createNumberBuilder({ type: 'number', hint: 'location.longitude' });\n },\n },\n\n /**\n * Phone-related fields\n */\n phone: {\n number(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'phone.number' });\n },\n },\n\n /**\n * Image-related fields\n */\n image: {\n avatar(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'image.avatar' });\n },\n url(options?: { width?: number; height?: number }): StringFieldBuilder {\n const hint = options ? `image.url:${options.width || 640}x${options.height || 480}` : 'image.url';\n return createStringBuilder({ type: 'string', hint });\n },\n },\n\n /**\n * Company-related fields\n */\n company: {\n name(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'company.name' });\n },\n catchPhrase(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'company.catchPhrase' });\n },\n },\n\n /**\n * Commerce-related fields\n */\n commerce: {\n productName(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'commerce.productName' });\n },\n price(): NumberFieldBuilder {\n return createNumberBuilder({ type: 'number', hint: 'commerce.price' });\n },\n department(): StringFieldBuilder {\n return createStringBuilder({ type: 'string', hint: 'commerce.department' });\n },\n },\n\n // -------------------------------------------------------------------------\n // Complex Types\n // -------------------------------------------------------------------------\n\n /**\n * Enum field with type-safe values\n * @param values - Allowed enum values\n *\n * @example\n * ```typescript\n * field.enum(['admin', 'user', 'guest']).default('user')\n * ```\n */\n enum<T extends string>(values: readonly T[]): EnumFieldBuilder<T> {\n return createEnumBuilder(values);\n },\n\n /**\n * Reference to another entity\n * @param target - Target entity name\n *\n * @example\n * ```typescript\n * field.ref('user') // References the 'user' entity\n * ```\n */\n ref(target: string): RefFieldBuilder {\n return createRefBuilder(target);\n },\n\n /**\n * Array of items\n * @param itemType - The field definition for array items\n *\n * @example\n * ```typescript\n * field.array(field.string()) // Array of strings\n * field.array(field.uuid()).length(5) // Fixed-length array\n * ```\n */\n array<T>(itemType: FieldBuilder<T>): ArrayFieldBuilder<T> {\n return createArrayBuilder(itemType as unknown as FieldDefinition<T>);\n },\n\n /**\n * Nested object with defined shape\n * @param shape - Object shape definition\n *\n * @example\n * ```typescript\n * field.object({\n * street: field.location.streetAddress(),\n * city: field.location.city(),\n * zip: field.location.zipCode(),\n * })\n * ```\n */\n object<T extends Record<string, FieldBuilder<unknown>>>(\n shape: T\n ): ObjectFieldBuilder<{ [K in keyof T]: T[K] extends FieldBuilder<infer U> ? U : never }> {\n type InferredType = { [K in keyof T]: T[K] extends FieldBuilder<infer U> ? U : never };\n return createObjectBuilder<InferredType>(shape as unknown as Record<string, FieldDefinition>);\n },\n\n /**\n * Computed field that derives its value from other fields or data\n * @param config - Computed field configuration\n *\n * @example\n * ```typescript\n * field.computed({\n * mock: () => faker.person.fullName(),\n * resolve: (entity) => `${entity.firstName} ${entity.lastName}`,\n * dependsOn: ['firstName', 'lastName'],\n * })\n * ```\n */\n computed<T>(config: {\n mock?: () => T;\n resolve: (entity: Record<string, unknown>, db: unknown, ctx: unknown) => T | Promise<T>;\n dependsOn?: string[];\n }): ComputedFieldDefinition<T> {\n return createComputedField(config);\n },\n};\n\nexport type { FieldBuilder, StringFieldBuilder, NumberFieldBuilder, DateFieldBuilder, EnumFieldBuilder };\n","/**\n * Relation builder functions for defining entity relationships.\n * Supports one-to-one, one-to-many, and many-to-many relationships.\n *\n * @module schema/relations\n * @category Schema\n *\n * @example\n * ```typescript\n * import { defineData, field, hasOne, hasMany, belongsTo } from 'schemock/schema';\n *\n * const User = defineData('user', {\n * id: field.uuid(),\n * profile: hasOne('userProfile', { foreignKey: 'userId' }),\n * posts: hasMany('post', { foreignKey: 'authorId' }),\n * });\n *\n * const Post = defineData('post', {\n * id: field.uuid(),\n * authorId: field.uuid(),\n * author: belongsTo('user', { foreignKey: 'authorId' }),\n * });\n * ```\n */\n\nimport type { RelationDefinition } from './types';\n\n/**\n * Options for hasOne relations (one-to-one)\n */\nexport interface HasOneOptions {\n /**\n * The foreign key field on the related entity.\n * @example For User -> Profile, foreignKey is 'userId' on Profile\n */\n foreignKey?: string;\n /**\n * Whether to eagerly load this relation by default.\n * When true, the relation is included in all queries.\n */\n eager?: boolean;\n}\n\n/**\n * Options for hasMany relations (one-to-many)\n */\nexport interface HasManyOptions {\n /**\n * The foreign key field on the related entity.\n * @example For User -> Posts, foreignKey is 'authorId' on Post\n */\n foreignKey?: string;\n /**\n * Default ordering for related items.\n * @example { createdAt: 'desc' }\n */\n orderBy?: Record<string, 'asc' | 'desc'>;\n /**\n * Default limit for related items.\n */\n limit?: number;\n /**\n * For many-to-many: the junction table entity name.\n * @example For User -> Followers (through Follow), through is 'follow'\n */\n through?: string;\n /**\n * For many-to-many: the other foreign key on the junction table.\n * @example For followers, otherKey might be 'followerId'\n */\n otherKey?: string;\n}\n\n/**\n * Options for belongsTo relations (inverse of hasOne/hasMany)\n */\nexport interface BelongsToOptions {\n /**\n * The foreign key field on THIS entity.\n * @example For Post -> Author, foreignKey is 'authorId' on Post\n */\n foreignKey?: string;\n /**\n * Whether to eagerly load this relation by default.\n */\n eager?: boolean;\n}\n\n/**\n * Defines a one-to-one relationship where this entity has one related entity.\n * The foreign key is stored on the related entity.\n *\n * @param target - The name of the related entity\n * @param options - Relation configuration\n * @returns RelationDefinition\n *\n * @example\n * ```typescript\n * // User has one profile\n * const User = defineData('user', {\n * id: field.uuid(),\n * profile: hasOne('userProfile', {\n * foreignKey: 'userId', // FK on UserProfile\n * eager: true, // Always include\n * }),\n * });\n *\n * // UserProfile table has userId column\n * const UserProfile = defineData('userProfile', {\n * id: field.uuid(),\n * userId: field.uuid(), // Foreign key\n * bio: field.string(),\n * });\n * ```\n */\nexport function hasOne(target: string, options?: HasOneOptions): RelationDefinition {\n return {\n type: 'hasOne',\n target,\n foreignKey: options?.foreignKey,\n eager: options?.eager,\n };\n}\n\n/**\n * Defines a one-to-many relationship where this entity has many related entities.\n * The foreign key is stored on the related entities.\n *\n * @param target - The name of the related entity\n * @param options - Relation configuration\n * @returns RelationDefinition\n *\n * @example\n * ```typescript\n * // User has many posts\n * const User = defineData('user', {\n * id: field.uuid(),\n * posts: hasMany('post', {\n * foreignKey: 'authorId',\n * orderBy: { createdAt: 'desc' },\n * limit: 10,\n * }),\n * });\n *\n * // Post table has authorId column\n * const Post = defineData('post', {\n * id: field.uuid(),\n * authorId: field.uuid(), // Foreign key\n * title: field.string(),\n * });\n * ```\n *\n * @example Many-to-many through junction table\n * ```typescript\n * // User has many followers (other users) through follows\n * const User = defineData('user', {\n * id: field.uuid(),\n * followers: hasMany('user', {\n * through: 'follow',\n * foreignKey: 'followingId', // Points to this user\n * otherKey: 'followerId', // Points to follower\n * }),\n * });\n *\n * // Junction table\n * const Follow = defineData('follow', {\n * id: field.uuid(),\n * followerId: field.uuid(),\n * followingId: field.uuid(),\n * });\n * ```\n */\nexport function hasMany(target: string, options?: HasManyOptions): RelationDefinition {\n return {\n type: 'hasMany',\n target,\n foreignKey: options?.foreignKey,\n orderBy: options?.orderBy,\n limit: options?.limit,\n through: options?.through,\n otherKey: options?.otherKey,\n };\n}\n\n/**\n * Defines an inverse relationship where this entity belongs to another entity.\n * The foreign key is stored on THIS entity.\n *\n * @param target - The name of the parent entity\n * @param options - Relation configuration\n * @returns RelationDefinition\n *\n * @example\n * ```typescript\n * // Post belongs to a user (author)\n * const Post = defineData('post', {\n * id: field.uuid(),\n * authorId: field.uuid(), // Foreign key on THIS entity\n * title: field.string(),\n *\n * author: belongsTo('user', {\n * foreignKey: 'authorId',\n * eager: true, // Always include author\n * }),\n * });\n * ```\n */\nexport function belongsTo(target: string, options?: BelongsToOptions): RelationDefinition {\n return {\n type: 'belongsTo',\n target,\n foreignKey: options?.foreignKey,\n eager: options?.eager,\n };\n}\n","/**\n * Primary API for defining entity schemas with full type inference.\n *\n * @module schema/define-data\n * @category Schema\n *\n * @example\n * ```typescript\n * import { defineData, field, hasMany, belongsTo } from 'schemock/schema';\n *\n * const User = defineData('user', {\n * id: field.uuid(),\n * name: field.person.fullName(),\n * email: field.internet.email().unique(),\n * role: field.enum(['admin', 'user']).default('user'),\n * createdAt: field.date().readOnly(),\n *\n * // Relations\n * posts: hasMany('post', { foreignKey: 'authorId' }),\n *\n * // Computed\n * postCount: field.computed({\n * mock: () => Math.floor(Math.random() * 100),\n * resolve: (user, db) => db.post.count({ where: { authorId: user.id } }),\n * }),\n * }, {\n * api: { basePath: '/api/users' },\n * timestamps: true,\n * });\n * ```\n */\n\nimport type {\n EntitySchema,\n EntityOptions,\n FieldDefinition,\n RelationDefinition,\n ComputedFieldDefinition,\n FieldBuilder,\n RLSConfig,\n} from './types';\nimport { isComputedField, isRelation } from './types';\n\n/**\n * Convert a FieldBuilder or FieldDefinition to a normalized FieldDefinition\n * This handles the property name differences between the two types\n */\nfunction convertToFieldDefinition(field: FieldBuilder<unknown> | FieldDefinition): FieldDefinition {\n // Check if it's already a FieldDefinition (has 'nullable' property pattern)\n // or if it's a FieldBuilder (has 'isNullable' property pattern)\n const isBuilder = 'isNullable' in field || 'isUnique' in field || 'isReadOnly' in field || 'defaultValue' in field;\n\n if (!isBuilder) {\n // Already a FieldDefinition, just return it\n return field as FieldDefinition;\n }\n\n // Convert FieldBuilder to FieldDefinition\n const builder = field as FieldBuilder<unknown>;\n const definition: FieldDefinition = {\n type: builder.type,\n hint: builder.hint,\n nullable: builder.isNullable,\n unique: builder.isUnique,\n readOnly: builder.isReadOnly,\n default: builder.defaultValue,\n constraints: builder.constraints,\n target: builder.target,\n values: builder.values,\n };\n\n // Handle nested items (for arrays) - items are already FieldDefinition\n if (builder.items) {\n definition.items = builder.items;\n }\n\n // Handle nested shape (for objects) - shape values are already FieldDefinition\n if (builder.shape) {\n definition.shape = builder.shape;\n }\n\n return definition;\n}\n\n/**\n * Field definitions input type - accepts field builders, relations, or computed fields\n */\nexport type FieldDefinitions = Record<\n string,\n FieldBuilder<unknown> | FieldDefinition | RelationDefinition | ComputedFieldDefinition\n>;\n\n/**\n * Defines an entity schema with fields, relations, and computed properties.\n * This is the primary API for creating data models in Schemock.\n *\n * @param name - Unique name for this entity (used for table/collection naming)\n * @param definitions - Field, relation, and computed field definitions\n * @param options - Optional entity configuration (API, timestamps, etc.)\n * @returns EntitySchema with full type inference\n *\n * @example Basic entity\n * ```typescript\n * const User = defineData('user', {\n * id: field.uuid(),\n * name: field.string(),\n * email: field.email().unique(),\n * });\n * ```\n *\n * @example With relations\n * ```typescript\n * const Post = defineData('post', {\n * id: field.uuid(),\n * title: field.string(),\n * authorId: field.uuid(),\n * author: belongsTo('user', { foreignKey: 'authorId' }),\n * });\n * ```\n *\n * @example With API configuration\n * ```typescript\n * const Product = defineData('product', {\n * id: field.uuid(),\n * name: field.commerce.productName(),\n * price: field.commerce.price(),\n * }, {\n * api: {\n * basePath: '/api/products',\n * operations: { list: true, get: true, create: true },\n * pagination: { style: 'offset', defaultLimit: 20 },\n * },\n * timestamps: true,\n * });\n * ```\n *\n * @example With Row-Level Security (generic context-based)\n * ```typescript\n * // Simple scope-based (works without users - e.g., API keys, services)\n * const Post = defineData('post', {\n * id: field.uuid(),\n * title: field.string(),\n * tenantId: field.uuid(),\n * }, {\n * rls: {\n * // Rows filtered by tenantId from context\n * scope: [{ field: 'tenantId', contextKey: 'tenantId' }],\n * },\n * });\n *\n * // User-based with owner field and bypass\n * const Comment = defineData('comment', {\n * id: field.uuid(),\n * content: field.string(),\n * authorId: field.uuid(),\n * }, {\n * rls: {\n * scope: [{ field: 'authorId', contextKey: 'userId' }],\n * bypass: [{ contextKey: 'role', values: ['admin'] }],\n * },\n * });\n *\n * // Custom policy functions (full flexibility)\n * const Document = defineData('document', {\n * id: field.uuid(),\n * title: field.string(),\n * ownerId: field.uuid(),\n * isPublic: field.boolean(),\n * }, {\n * rls: {\n * select: (row, ctx) => row.isPublic || row.ownerId === ctx?.userId,\n * insert: (row, ctx) => row.ownerId === ctx?.userId,\n * },\n * });\n * ```\n */\nexport function defineData<T extends FieldDefinitions>(\n name: string,\n definitions: T,\n options?: EntityOptions\n): EntitySchema<T> {\n // Separate fields, relations, and computed fields\n const fields: Record<string, FieldDefinition> = {};\n const relations: Record<string, RelationDefinition> = {};\n const computed: Record<string, ComputedFieldDefinition> = {};\n\n for (const [key, value] of Object.entries(definitions)) {\n if (isComputedField(value)) {\n computed[key] = value;\n } else if (isRelation(value)) {\n relations[key] = value;\n } else {\n // It's a field definition or field builder - convert to FieldDefinition\n const fieldValue = value as FieldBuilder<unknown> | FieldDefinition;\n fields[key] = convertToFieldDefinition(fieldValue);\n }\n }\n\n // Add automatic id field if not present\n if (!fields.id) {\n fields.id = {\n type: 'uuid',\n hint: 'string.uuid',\n readOnly: true,\n };\n }\n\n // Add timestamp fields if enabled (default: true)\n const timestamps = options?.timestamps ?? true;\n if (timestamps) {\n if (!fields.createdAt) {\n fields.createdAt = {\n type: 'date',\n hint: 'date.past',\n readOnly: true,\n };\n }\n if (!fields.updatedAt) {\n fields.updatedAt = {\n type: 'date',\n hint: 'date.recent',\n readOnly: true,\n };\n }\n }\n\n const schema: EntitySchema<T> = {\n name,\n fields,\n timestamps,\n api: options?.api,\n rls: options?.rls,\n };\n\n // Only add relations/computed if non-empty\n if (Object.keys(relations).length > 0) {\n schema.relations = relations;\n }\n if (Object.keys(computed).length > 0) {\n schema.computed = computed;\n }\n\n return schema;\n}\n","/**\n * API for defining computed views over entity schemas.\n * Views provide custom projections of data with embedded relations and computed fields.\n *\n * @module schema/define-view\n * @category Schema\n *\n * @example\n * ```typescript\n * import { defineView, embed, pick } from 'schemock/schema';\n *\n * const UserFullView = defineView('user-full', {\n * ...pick(User, ['id', 'name', 'email']),\n * profile: embed(UserProfile),\n * recentPosts: embed(Post, { limit: 5, orderBy: { createdAt: 'desc' } }),\n * stats: {\n * postCount: field.computed({...}),\n * totalViews: field.computed({...}),\n * },\n * }, {\n * endpoint: '/api/users/:id/full',\n * params: ['id'],\n * });\n * ```\n */\n\nimport type {\n ViewSchema,\n ViewFields,\n ViewOptions,\n EntitySchema,\n FieldDefinition,\n EmbedConfig,\n ComputedFieldDefinition,\n} from './types';\n\n/**\n * Embed marker for including related entity data in a view\n */\nexport interface EmbedMarker<T = unknown> {\n /** Marker to identify embedded fields */\n _embed: true;\n /** The source entity schema */\n entity: EntitySchema<T>;\n /** Embed configuration */\n config?: EmbedConfig;\n}\n\n/**\n * Creates an embed marker for including related entity data in a view.\n * Embedded data is fetched and included as part of the view response.\n *\n * @param entity - The entity schema to embed\n * @param config - Optional embed configuration (limit, orderBy, select)\n * @returns EmbedMarker\n *\n * @example Basic embed\n * ```typescript\n * const UserView = defineView('user-view', {\n * id: field.uuid(),\n * profile: embed(UserProfile),\n * }, { endpoint: '/api/users/:id', params: ['id'] });\n * ```\n *\n * @example Embed with options\n * ```typescript\n * const UserView = defineView('user-view', {\n * id: field.uuid(),\n * recentPosts: embed(Post, {\n * limit: 5,\n * orderBy: { createdAt: 'desc' },\n * select: ['id', 'title', 'createdAt'],\n * }),\n * }, { endpoint: '/api/users/:id', params: ['id'] });\n * ```\n */\nexport function embed<T>(entity: EntitySchema<T>, config?: EmbedConfig): EmbedMarker<T> {\n return {\n _embed: true,\n entity,\n config,\n };\n}\n\n/**\n * Type guard to check if a value is an embed marker\n */\nexport function isEmbedMarker(value: unknown): value is EmbedMarker {\n return typeof value === 'object' && value !== null && '_embed' in value && (value as EmbedMarker)._embed === true;\n}\n\n/**\n * Picks specific fields from an entity schema to include in a view.\n * This allows selecting a subset of fields without manually copying definitions.\n *\n * @param entity - The source entity schema\n * @param fields - Array of field names to include\n * @returns Record of picked field definitions\n *\n * @example\n * ```typescript\n * const UserView = defineView('user-view', {\n * ...pick(User, ['id', 'name', 'email']),\n * // Additional view-specific fields...\n * }, { endpoint: '/api/users/:id', params: ['id'] });\n * ```\n */\nexport function pick<T extends EntitySchema, K extends keyof T['fields']>(\n entity: T,\n fields: K[]\n): Record<K, T['fields'][K]> {\n const result = {} as Record<K, T['fields'][K]>;\n for (const fieldName of fields) {\n if (fieldName in entity.fields) {\n result[fieldName] = entity.fields[fieldName as string] as T['fields'][K];\n }\n }\n return result;\n}\n\n/**\n * Omits specific fields from an entity schema.\n * This is the inverse of pick - includes all fields except the specified ones.\n *\n * @param entity - The source entity schema\n * @param fields - Array of field names to exclude\n * @returns Record of remaining field definitions\n *\n * @example\n * ```typescript\n * const UserView = defineView('user-view', {\n * ...omit(User, ['password', 'internalNotes']),\n * }, { endpoint: '/api/users/:id', params: ['id'] });\n * ```\n */\nexport function omit<T extends EntitySchema, K extends keyof T['fields']>(\n entity: T,\n fields: K[]\n): Omit<T['fields'], K> {\n const result = { ...entity.fields };\n for (const fieldName of fields) {\n delete result[fieldName as string];\n }\n return result as Omit<T['fields'], K>;\n}\n\n/**\n * Input type for view field definitions\n */\nexport type ViewFieldDefinitions = Record<\n string,\n FieldDefinition | ComputedFieldDefinition | EmbedMarker | Record<string, FieldDefinition | ComputedFieldDefinition>\n>;\n\n/**\n * Defines a computed view over entity schemas.\n * Views provide custom API endpoints that project, combine, and compute data\n * from one or more entities.\n *\n * @param name - Unique name for this view\n * @param fields - View field definitions (fields, embeds, computed, nested objects)\n * @param options - View configuration (endpoint, params)\n * @returns ViewSchema\n *\n * @example Basic view\n * ```typescript\n * const UserProfile = defineView('user-profile', {\n * id: field.uuid(),\n * name: field.string(),\n * avatar: field.string(),\n * }, {\n * endpoint: '/api/users/:id/profile',\n * params: ['id'],\n * });\n * ```\n *\n * @example View with embeds and computed fields\n * ```typescript\n * const UserFullView = defineView('user-full', {\n * // Pick fields from User entity\n * ...pick(User, ['id', 'name', 'email', 'role']),\n *\n * // Embed related profile\n * profile: embed(UserProfile),\n *\n * // Embed recent posts with config\n * recentPosts: embed(Post, {\n * limit: 5,\n * orderBy: { createdAt: 'desc' },\n * }),\n *\n * // Nested computed stats\n * stats: {\n * postCount: field.computed({\n * mock: () => Math.floor(Math.random() * 50),\n * resolve: (_, db, ctx) => db.post.count({\n * where: { authorId: ctx.params.id }\n * }),\n * }),\n * totalViews: field.computed({\n * mock: () => Math.floor(Math.random() * 50000),\n * resolve: (data) => data.recentPosts?.reduce(\n * (sum, p) => sum + p.viewCount, 0\n * ) ?? 0,\n * }),\n * },\n * }, {\n * endpoint: '/api/users/:id/full',\n * params: ['id'],\n * });\n * ```\n */\nexport function defineView(name: string, fields: ViewFieldDefinitions, options: ViewOptions): ViewSchema {\n // Process fields to convert embed markers to proper ViewFields format\n const processedFields: ViewFields = {};\n\n for (const [key, value] of Object.entries(fields)) {\n if (isEmbedMarker(value)) {\n processedFields[key] = {\n _embed: true,\n entity: value.entity,\n config: value.config,\n };\n } else if (typeof value === 'object' && value !== null && !('type' in value) && !('_computed' in value)) {\n // It's a nested object of fields (like stats: { postCount: ... })\n processedFields[key] = value as Record<string, FieldDefinition | ComputedFieldDefinition>;\n } else {\n // It's a regular field or computed field\n processedFields[key] = value as FieldDefinition | ComputedFieldDefinition;\n }\n }\n\n return {\n name,\n fields: processedFields,\n endpoint: options.endpoint,\n params: options.params,\n };\n}\n","/**\n * API for defining custom endpoints with mock resolvers.\n * Enables mocking of arbitrary REST APIs beyond standard CRUD operations.\n *\n * @module schema/define-endpoint\n * @category Schema\n *\n * @example\n * ```typescript\n * import { defineEndpoint, field } from 'schemock/schema';\n *\n * // GET endpoint with query parameters\n * const SearchEndpoint = defineEndpoint('/api/search', {\n * method: 'GET',\n * params: {\n * q: field.string(),\n * type: field.enum(['user', 'post', 'all']).default('all'),\n * limit: field.number.int().default(20),\n * },\n * response: {\n * results: field.array(field.object({\n * id: field.string(),\n * title: field.string(),\n * })),\n * total: field.number.int(),\n * },\n * mockResolver: async ({ params, db }) => {\n * const users = db.user.findMany({\n * where: { name: { contains: params.q } }\n * });\n * return { results: users, total: users.length };\n * },\n * });\n *\n * // POST endpoint with body\n * const CreateOrderEndpoint = defineEndpoint('/api/orders', {\n * method: 'POST',\n * body: {\n * items: field.array(field.object({\n * productId: field.string(),\n * quantity: field.number.int(),\n * })),\n * },\n * response: {\n * orderId: field.string(),\n * total: field.number.float(),\n * },\n * mockResolver: async ({ body }) => ({\n * orderId: crypto.randomUUID(),\n * total: body.items.reduce((sum, item) => sum + item.quantity * 10, 0),\n * }),\n * });\n * ```\n */\n\nimport type {\n EndpointSchema,\n EndpointConfig,\n FieldDefinition,\n FieldBuilder,\n} from './types';\n\n/**\n * Convert a FieldBuilder or FieldDefinition to a normalized FieldDefinition.\n * This handles the property name differences between the two types.\n */\nfunction normalizeField(field: FieldBuilder<unknown> | FieldDefinition): FieldDefinition {\n // Check if it's already a FieldDefinition (has 'nullable' property pattern)\n // or if it's a FieldBuilder (has 'isNullable' property pattern)\n const isBuilder =\n 'isNullable' in field || 'isUnique' in field || 'isReadOnly' in field || 'defaultValue' in field;\n\n if (!isBuilder) {\n // Already a FieldDefinition, just return it\n return field as FieldDefinition;\n }\n\n // Convert FieldBuilder to FieldDefinition\n const builder = field as FieldBuilder<unknown>;\n const definition: FieldDefinition = {\n type: builder.type,\n hint: builder.hint,\n nullable: builder.isNullable,\n unique: builder.isUnique,\n readOnly: builder.isReadOnly,\n default: builder.defaultValue,\n constraints: builder.constraints,\n target: builder.target,\n values: builder.values,\n };\n\n // Handle nested items (for arrays)\n if (builder.items) {\n definition.items = builder.items;\n }\n\n // Handle nested shape (for objects)\n if (builder.shape) {\n definition.shape = builder.shape;\n }\n\n return definition;\n}\n\n/**\n * Normalize a record of fields (params, body, or response)\n */\nfunction normalizeFields(\n fields: Record<string, FieldBuilder<unknown> | FieldDefinition> | undefined\n): Record<string, FieldDefinition> {\n const result: Record<string, FieldDefinition> = {};\n\n if (!fields) return result;\n\n for (const [key, value] of Object.entries(fields)) {\n result[key] = normalizeField(value);\n }\n\n return result;\n}\n\n/**\n * Defines a custom API endpoint with mock resolver.\n * Use this to mock arbitrary REST endpoints beyond standard CRUD operations.\n *\n * @param path - URL path (e.g., '/api/search', '/api/orders/:id')\n * @param config - Endpoint configuration including method, params, body, response, and mockResolver\n * @returns EndpointSchema\n *\n * @example Simple GET endpoint\n * ```typescript\n * const HealthCheck = defineEndpoint('/api/health', {\n * method: 'GET',\n * response: {\n * status: field.enum(['ok', 'degraded', 'down']),\n * timestamp: field.date(),\n * },\n * mockResolver: () => ({\n * status: 'ok',\n * timestamp: new Date(),\n * }),\n * });\n * ```\n *\n * @example GET with path parameters\n * ```typescript\n * const UserStats = defineEndpoint('/api/users/:userId/stats', {\n * method: 'GET',\n * params: {\n * userId: field.string(),\n * },\n * response: {\n * totalPosts: field.number.int(),\n * totalViews: field.number.int(),\n * },\n * mockResolver: async ({ params, db }) => {\n * const posts = db.post.findMany({\n * where: { authorId: { equals: params.userId } }\n * });\n * return {\n * totalPosts: posts.length,\n * totalViews: posts.reduce((sum, p) => sum + p.views, 0),\n * };\n * },\n * });\n * ```\n *\n * @example POST with body\n * ```typescript\n * const BulkDelete = defineEndpoint('/api/posts/bulk-delete', {\n * method: 'POST',\n * body: {\n * ids: field.array(field.string()),\n * },\n * response: {\n * deleted: field.number.int(),\n * },\n * mockResolver: async ({ body, db }) => {\n * let deleted = 0;\n * for (const id of body.ids) {\n * const result = db.post.delete({ where: { id: { equals: id } } });\n * if (result) deleted++;\n * }\n * return { deleted };\n * },\n * });\n * ```\n */\nexport function defineEndpoint<\n TParams = Record<string, unknown>,\n TBody = Record<string, unknown>,\n TResponse = unknown,\n>(\n path: string,\n config: EndpointConfig<TParams, TBody, TResponse>\n): EndpointSchema<TParams, TBody, TResponse> {\n // Validate path\n if (!path.startsWith('/')) {\n throw new Error(`Endpoint path must start with '/': ${path}`);\n }\n\n // Normalize all field definitions\n const params = normalizeFields(config.params);\n const body = normalizeFields(config.body);\n const response = normalizeFields(config.response);\n\n // Validate body is only used with methods that support it\n if (Object.keys(body).length > 0 && config.method === 'GET') {\n console.warn(`Warning: GET endpoints typically don't have a body. Consider using params instead for ${path}`);\n }\n\n return {\n path,\n method: config.method,\n params,\n body,\n response,\n mockResolver: config.mockResolver,\n description: config.description,\n _endpoint: true as const,\n };\n}\n"]}
@@ -0,0 +1,96 @@
1
+ import { a as AdapterContext, b as AdapterResponse } from './types-c2AN3vky.js';
2
+
3
+ /**
4
+ * Middleware Types - Interfaces for the middleware chain
5
+ *
6
+ * @module middleware/types
7
+ * @category Middleware
8
+ */
9
+
10
+ /**
11
+ * Result returned by middleware hooks.
12
+ */
13
+ interface MiddlewareResult {
14
+ /** Whether to continue to the next middleware */
15
+ continue: boolean;
16
+ /** Modified response (for short-circuiting) */
17
+ response?: AdapterResponse<unknown>;
18
+ /** Error to throw */
19
+ error?: Error;
20
+ }
21
+ /**
22
+ * Middleware function type (alternative style).
23
+ *
24
+ * Middleware can intercept requests before they reach the adapter
25
+ * and responses before they return to the caller.
26
+ */
27
+ type MiddlewareFunction = <T>(ctx: MiddlewareContext, next: () => Promise<AdapterResponse<T>>) => Promise<AdapterResponse<T>>;
28
+ /**
29
+ * Middleware interface with before/after/onError hooks.
30
+ *
31
+ * All middleware must implement this interface.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const loggerMiddleware: Middleware = {
36
+ * name: 'logger',
37
+ * before: async (ctx) => {
38
+ * console.log(`Request: ${ctx.operation} ${ctx.entity}`);
39
+ * },
40
+ * after: async (ctx, response) => {
41
+ * console.log(`Response: ${ctx.operation} completed`);
42
+ * return response;
43
+ * },
44
+ * };
45
+ * ```
46
+ */
47
+ interface Middleware {
48
+ /** Unique name for this middleware */
49
+ name: string;
50
+ /**
51
+ * Called before the request is executed.
52
+ * Can modify context or short-circuit the request.
53
+ */
54
+ before?: (ctx: MiddlewareContext) => Promise<MiddlewareResult | void>;
55
+ /**
56
+ * Called after the response is received.
57
+ * Can modify the response before returning.
58
+ */
59
+ after?: <T>(ctx: MiddlewareContext, response: AdapterResponse<T>) => Promise<AdapterResponse<T>>;
60
+ /**
61
+ * Called when an error occurs.
62
+ * Can handle the error or re-throw.
63
+ */
64
+ onError?: (ctx: MiddlewareContext, error: Error) => Promise<MiddlewareResult | void>;
65
+ /**
66
+ * Alternative: single handler function (Koa-style).
67
+ * If provided, before/after/onError are ignored.
68
+ */
69
+ handler?: MiddlewareFunction;
70
+ /** Whether this middleware is enabled */
71
+ enabled?: boolean;
72
+ }
73
+ /**
74
+ * Middleware context passed through the chain.
75
+ */
76
+ interface MiddlewareContext extends AdapterContext {
77
+ /** The operation being performed (findOne, findMany, create, update, delete) */
78
+ operation: string;
79
+ /** Start time of the request (milliseconds) */
80
+ startTime?: number;
81
+ /** Request metadata added by middleware */
82
+ metadata: Record<string, unknown>;
83
+ /** Whether to skip cache */
84
+ skipCache?: boolean;
85
+ /** Current retry count */
86
+ retryCount?: number;
87
+ /** Headers to include in request (for fetch-based adapters) */
88
+ headers?: Record<string, string>;
89
+ /**
90
+ * Execution context extracted from headers (user info, tenant, etc.)
91
+ * Populated by context middleware from Authorization header and other custom headers.
92
+ */
93
+ context?: Record<string, unknown>;
94
+ }
95
+
96
+ export type { Middleware as M, MiddlewareFunction as a, MiddlewareContext as b, MiddlewareResult as c };