{"modulePath":"github.com/bitechdev/ResolveSpec","version":"v1.0.78","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package resolvespec\n\n## Functions\n\n```go\nfunc ExampleBunRouterWithBunDB(bunDB *bun.DB)\n```\nExampleBunRouterWithBunDB shows the full uptrace stack (bunrouter + Bun ORM)\n\n```go\nfunc ExampleBunRouterWithBunDBAndAuth(bunDB *bun.DB)\n```\nExampleBunRouterWithBunDBAndAuth shows the full uptrace stack with authentication\n\n```go\nfunc ExampleBunRouterWithGroup(bunDB *bun.DB)\n```\nExampleBunRouterWithGroup shows how to use SetupBunRouterRoutes with a bunrouter.Group\n\n```go\nfunc ExampleWithBun(bunDB *bun.DB)\n```\nExampleWithBun shows how to switch to Bun ORM\n\n```go\nfunc ExampleWithBunAndAuth(bunDB *bun.DB)\n```\nExampleWithBunAndAuth shows how to use ResolveSpec with Bun and authentication\n\n```go\nfunc ExampleWithBunRouter(bunDB *bun.DB)\n```\nExampleWithBunRouter shows how to use bunrouter from uptrace\n\n```go\nfunc ExampleWithGORM(db *gorm.DB)\n```\nExampleWithGORM shows how to use ResolveSpec with GORM\n\n```go\nfunc ExampleWithGORMAndAuth(db *gorm.DB)\n```\nExampleWithGORMAndAuth shows how to use ResolveSpec with GORM and authentication\n\n```go\nfunc GetCursorFilter(\n\ttableName string,\n\tpkName string,\n\tmodelColumns []string,\n\toptions common.RequestOptions,\n\texpandJoins map[string]string,\n) (string, error)\n```\nGetCursorFilter generates a SQL \\`EXISTS\\` subquery for cursor-based pagination. It uses the current request's sort and cursor values.\n\nParameters:\n\n  - tableName: name of the main table (e.g. \"posts\")\n  - pkName: primary key column (e.g. \"id\")\n  - modelColumns: optional list of valid main-table columns (for validation). Pass nil to skip.\n  - options: the request options containing sort and cursor information\n  - expandJoins: optional map\\[alias]string of JOIN clauses for join-column sort support\n\nReturns SQL snippet to embed in WHERE clause.\n\n```go\nfunc GetEntity(ctx context.Context) string\n```\nGetEntity retrieves entity from context\n\n```go\nfunc GetModel(ctx context.Context) interface{}\n```\nGetModel retrieves model from context\n\n```go\nfunc GetModelPtr(ctx context.Context) interface{}\n```\nGetModelPtr retrieves model pointer from context\n\n```go\nfunc GetSchema(ctx context.Context) string\n```\nGetSchema retrieves schema from context\n\n```go\nfunc GetTableName(ctx context.Context) string\n```\nGetTableName retrieves table name from context\n\n```go\nfunc NewStandardBunRouter() *router.StandardBunRouterAdapter\n```\nNewStandardBunRouter creates a router with standard BunRouter handlers\n\n```go\nfunc NewStandardMuxRouter() *router.StandardMuxAdapter\n```\nNewStandardMuxRouter creates a router with standard Mux HTTP handlers\n\n```go\nfunc RegisterSecurityHooks(handler *Handler, securityList *security.SecurityList)\n```\nRegisterSecurityHooks registers all security-related hooks with the handler\n\n```go\nfunc SetupBunRouterRoutes(r BunRouterHandler, handler *Handler, authMiddleware MiddlewareFunc)\n```\nSetupBunRouterRoutes sets up bunrouter routes for the ResolveSpec API Accepts bunrouter.Router or bunrouter.Group authMiddleware is optional - if provided, routes will be protected with the middleware\n\n```go\nfunc SetupMuxRoutes(muxRouter *mux.Router, handler *Handler, authMiddleware MiddlewareFunc)\n```\nSetupMuxRoutes sets up routes for the ResolveSpec API with Mux authMiddleware is optional - if provided, routes will be protected with the middleware Example: SetupMuxRoutes(router, handler, func(h http.Handler) http.Handler { return security.NewAuthHandler(securityList, h) })\n\n```go\nfunc WithEntity(ctx context.Context, entity string) context.Context\n```\nWithEntity adds entity to context\n\n```go\nfunc WithModel(ctx context.Context, model interface{}) context.Context\n```\nWithModel adds model to context\n\n```go\nfunc WithModelPtr(ctx context.Context, modelPtr interface{}) context.Context\n```\nWithModelPtr adds model pointer to context\n\n```go\nfunc WithRequestData(ctx context.Context, schema, entity, tableName string, model, modelPtr interface{}) context.Context\n```\nWithRequestData adds all request-scoped data to context at once\n\n```go\nfunc WithSchema(ctx context.Context, schema string) context.Context\n```\nWithSchema adds schema to context\n\n```go\nfunc WithTableName(ctx context.Context, tableName string) context.Context\n```\nWithTableName adds table name to context\n\n## Types\n\n```go\ntype BunRouterHandler interface {\n\tHandle(method, path string, handler bunrouter.HandlerFunc)\n}\n```\nBunRouterHandler is an interface that both bunrouter.Router and bunrouter.Group implement\n\n```go\ntype CursorDirection int\n```\nCursorDirection defines pagination direction\n\n```go\nconst (\n\tCursorForward  CursorDirection = 1\n\tCursorBackward CursorDirection = -1\n)\n```\n\n```go\ntype FallbackHandler func(w common.ResponseWriter, r common.Request, params map[string]string)\n```\nFallbackHandler is a function that handles requests when no model is found It receives the same parameters as the Handle method\n\n```go\ntype GormTableCRUDRequest struct {\n\tRequest *string `json:\"_request\"`\n}\n```\n\n```go\nfunc (r GormTableCRUDRequest) GetRequest() string\n```\n\n```go\nfunc (r *GormTableCRUDRequest) SetRequest(request string)\n```\n\n```go\ntype GormTableNameInterface interface {\n\tTableName() string\n}\n```\nLegacy interfaces for backward compatibility\n\n```go\ntype GormTableSchemaInterface interface {\n\tTableSchema() string\n}\n```\n\n```go\ntype Handler struct {\n\t// contains filtered or unexported fields\n}\n```\nHandler handles API requests using database and model abstractions\n\n```go\nfunc NewHandler(db common.Database, registry common.ModelRegistry) *Handler\n```\nNewHandler creates a new API handler with database and registry abstractions\n\n```go\nfunc NewHandlerWithBun(db *bun.DB) *Handler\n```\nNewHandlerWithBun creates a new Handler with Bun adapter\n\n```go\nfunc NewHandlerWithGORM(db *gorm.DB) *Handler\n```\nNewHandlerWithGORM creates a new Handler with GORM adapter\n\n```go\nfunc (h *Handler) GetDatabase() common.Database\n```\nGetDatabase returns the underlying database connection Implements common.SpecHandler interface\n\n```go\nfunc (h *Handler) GetRelationshipInfo(modelType reflect.Type, relationName string) *common.RelationshipInfo\n```\nGetRelationshipInfo implements common.RelationshipInfoProvider interface\n\n```go\nfunc (h *Handler) Handle(w common.ResponseWriter, r common.Request, params map[string]string)\n```\nHandle processes API requests through router-agnostic interface\n\n```go\nfunc (h *Handler) HandleGet(w common.ResponseWriter, r common.Request, params map[string]string)\n```\nHandleGet processes GET requests for metadata\n\n```go\nfunc (h *Handler) HandleOpenAPI(w common.ResponseWriter, r common.Request)\n```\nHandleOpenAPI generates and returns the OpenAPI specification\n\n```go\nfunc (h *Handler) Hooks() *HookRegistry\n```\nHooks returns the hook registry for this handler Use this to register custom hooks for operations\n\n```go\nfunc (h *Handler) RegisterModel(schema, name string, model interface{}) error\n```\nRegisterModel allows registering models at runtime\n\n```go\nfunc (h *Handler) SetFallbackHandler(fallback FallbackHandler)\n```\nSetFallbackHandler sets a fallback handler to be called when no model is found If not set, the handler will simply return (pass through to next route)\n\n```go\nfunc (h *Handler) SetOpenAPIGenerator(generator func() (string, error))\n```\nSetOpenAPIGenerator sets the OpenAPI generator function\n\n```go\ntype HookContext struct {\n\tContext context.Context\n\tHandler *Handler // Reference to the handler for accessing database, registry, etc.\n\tSchema  string\n\tEntity  string\n\tModel   interface{}\n\tOptions common.RequestOptions\n\tWriter  common.ResponseWriter\n\tRequest common.Request\n\n\t// Operation being dispatched (e.g. \"read\", \"create\", \"update\", \"delete\")\n\tOperation string\n\n\t// Operation-specific fields\n\tID     string\n\tData   interface{} // For create/update operations\n\tResult interface{} // For after hooks\n\tError  error       // For after hooks\n\n\t// Query chain - allows hooks to modify the query before execution\n\tQuery common.SelectQuery\n\n\t// Allow hooks to abort the operation\n\tAbort        bool   // If set to true, the operation will be aborted\n\tAbortMessage string // Message to return if aborted\n\tAbortCode    int    // HTTP status code if aborted\n\n\t// Tx provides access to the database/transaction for executing additional SQL\n\t// This allows hooks to run custom queries in addition to the main Query chain\n\tTx common.Database\n}\n```\nHookContext contains all the data available to a hook\n\n```go\ntype HookFunc func(*HookContext) error\n```\nHookFunc is the signature for hook functions It receives a HookContext and can modify it or return an error If an error is returned, the operation will be aborted\n\n```go\ntype HookRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nHookRegistry manages all registered hooks\n\n```go\nfunc NewHookRegistry() *HookRegistry\n```\nNewHookRegistry creates a new hook registry\n\n```go\nfunc (r *HookRegistry) Clear(hookType HookType)\n```\nClear removes all hooks for the specified type\n\n```go\nfunc (r *HookRegistry) ClearAll()\n```\nClearAll removes all registered hooks\n\n```go\nfunc (r *HookRegistry) Count(hookType HookType) int\n```\nCount returns the number of hooks registered for a specific type\n\n```go\nfunc (r *HookRegistry) Execute(hookType HookType, ctx *HookContext) error\n```\nExecute runs all hooks for the specified type in order If any hook returns an error, execution stops and the error is returned\n\n```go\nfunc (r *HookRegistry) GetAllHookTypes() []HookType\n```\nGetAllHookTypes returns all hook types that have registered hooks\n\n```go\nfunc (r *HookRegistry) HasHooks(hookType HookType) bool\n```\nHasHooks returns true if there are any hooks registered for the specified type\n\n```go\nfunc (r *HookRegistry) Register(hookType HookType, hook HookFunc)\n```\nRegister adds a new hook for the specified hook type\n\n```go\nfunc (r *HookRegistry) RegisterMultiple(hookTypes []HookType, hook HookFunc)\n```\nRegisterMultiple registers a hook for multiple hook types\n\n```go\ntype HookType string\n```\nHookType defines the type of hook to execute\n\n```go\nconst (\n\t// BeforeHandle fires after model resolution, before operation dispatch.\n\t// Use this for auth checks that need model rules and user context simultaneously.\n\tBeforeHandle HookType = \"before_handle\"\n\n\t// Read operation hooks\n\tBeforeRead HookType = \"before_read\"\n\tAfterRead  HookType = \"after_read\"\n\n\t// Create operation hooks\n\tBeforeCreate HookType = \"before_create\"\n\tAfterCreate  HookType = \"after_create\"\n\n\t// Update operation hooks\n\tBeforeUpdate HookType = \"before_update\"\n\tAfterUpdate  HookType = \"after_update\"\n\n\t// Delete operation hooks\n\tBeforeDelete HookType = \"before_delete\"\n\tAfterDelete  HookType = \"after_delete\"\n\n\t// Scan/Execute operation hooks (for query building)\n\tBeforeScan HookType = \"before_scan\"\n)\n```\n\n```go\ntype MiddlewareFunc func(http.Handler) http.Handler\n```\nMiddlewareFunc is a function that wraps an http.Handler with additional functionality\n\n","path":"github.com/bitechdev/ResolveSpec/pkg/resolvespec","name":"resolvespec","synopsis":"","isRedistributable":true}
