github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/privacy/privacy.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package privacy 4 5 import ( 6 "context" 7 "fmt" 8 9 "github.com/NpoolPlatform/chain-middleware/pkg/db/ent" 10 11 "entgo.io/ent/entql" 12 "entgo.io/ent/privacy" 13 ) 14 15 var ( 16 // Allow may be returned by rules to indicate that the policy 17 // evaluation should terminate with allow decision. 18 Allow = privacy.Allow 19 20 // Deny may be returned by rules to indicate that the policy 21 // evaluation should terminate with deny decision. 22 Deny = privacy.Deny 23 24 // Skip may be returned by rules to indicate that the policy 25 // evaluation should continue to the next rule. 26 Skip = privacy.Skip 27 ) 28 29 // Allowf returns an formatted wrapped Allow decision. 30 func Allowf(format string, a ...interface{}) error { 31 return fmt.Errorf(format+": %w", append(a, Allow)...) 32 } 33 34 // Denyf returns an formatted wrapped Deny decision. 35 func Denyf(format string, a ...interface{}) error { 36 return fmt.Errorf(format+": %w", append(a, Deny)...) 37 } 38 39 // Skipf returns an formatted wrapped Skip decision. 40 func Skipf(format string, a ...interface{}) error { 41 return fmt.Errorf(format+": %w", append(a, Skip)...) 42 } 43 44 // DecisionContext creates a new context from the given parent context with 45 // a policy decision attach to it. 46 func DecisionContext(parent context.Context, decision error) context.Context { 47 return privacy.DecisionContext(parent, decision) 48 } 49 50 // DecisionFromContext retrieves the policy decision from the context. 51 func DecisionFromContext(ctx context.Context) (error, bool) { 52 return privacy.DecisionFromContext(ctx) 53 } 54 55 type ( 56 // Policy groups query and mutation policies. 57 Policy = privacy.Policy 58 59 // QueryRule defines the interface deciding whether a 60 // query is allowed and optionally modify it. 61 QueryRule = privacy.QueryRule 62 // QueryPolicy combines multiple query rules into a single policy. 63 QueryPolicy = privacy.QueryPolicy 64 65 // MutationRule defines the interface which decides whether a 66 // mutation is allowed and optionally modifies it. 67 MutationRule = privacy.MutationRule 68 // MutationPolicy combines multiple mutation rules into a single policy. 69 MutationPolicy = privacy.MutationPolicy 70 ) 71 72 // QueryRuleFunc type is an adapter to allow the use of 73 // ordinary functions as query rules. 74 type QueryRuleFunc func(context.Context, ent.Query) error 75 76 // Eval returns f(ctx, q). 77 func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 78 return f(ctx, q) 79 } 80 81 // MutationRuleFunc type is an adapter which allows the use of 82 // ordinary functions as mutation rules. 83 type MutationRuleFunc func(context.Context, ent.Mutation) error 84 85 // EvalMutation returns f(ctx, m). 86 func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 87 return f(ctx, m) 88 } 89 90 // QueryMutationRule is an interface which groups query and mutation rules. 91 type QueryMutationRule interface { 92 QueryRule 93 MutationRule 94 } 95 96 // AlwaysAllowRule returns a rule that returns an allow decision. 97 func AlwaysAllowRule() QueryMutationRule { 98 return fixedDecision{Allow} 99 } 100 101 // AlwaysDenyRule returns a rule that returns a deny decision. 102 func AlwaysDenyRule() QueryMutationRule { 103 return fixedDecision{Deny} 104 } 105 106 type fixedDecision struct { 107 decision error 108 } 109 110 func (f fixedDecision) EvalQuery(context.Context, ent.Query) error { 111 return f.decision 112 } 113 114 func (f fixedDecision) EvalMutation(context.Context, ent.Mutation) error { 115 return f.decision 116 } 117 118 type contextDecision struct { 119 eval func(context.Context) error 120 } 121 122 // ContextQueryMutationRule creates a query/mutation rule from a context eval func. 123 func ContextQueryMutationRule(eval func(context.Context) error) QueryMutationRule { 124 return contextDecision{eval} 125 } 126 127 func (c contextDecision) EvalQuery(ctx context.Context, _ ent.Query) error { 128 return c.eval(ctx) 129 } 130 131 func (c contextDecision) EvalMutation(ctx context.Context, _ ent.Mutation) error { 132 return c.eval(ctx) 133 } 134 135 // OnMutationOperation evaluates the given rule only on a given mutation operation. 136 func OnMutationOperation(rule MutationRule, op ent.Op) MutationRule { 137 return MutationRuleFunc(func(ctx context.Context, m ent.Mutation) error { 138 if m.Op().Is(op) { 139 return rule.EvalMutation(ctx, m) 140 } 141 return Skip 142 }) 143 } 144 145 // DenyMutationOperationRule returns a rule denying specified mutation operation. 146 func DenyMutationOperationRule(op ent.Op) MutationRule { 147 rule := MutationRuleFunc(func(_ context.Context, m ent.Mutation) error { 148 return Denyf("ent/privacy: operation %s is not allowed", m.Op()) 149 }) 150 return OnMutationOperation(rule, op) 151 } 152 153 // The AppCoinQueryRuleFunc type is an adapter to allow the use of ordinary 154 // functions as a query rule. 155 type AppCoinQueryRuleFunc func(context.Context, *ent.AppCoinQuery) error 156 157 // EvalQuery return f(ctx, q). 158 func (f AppCoinQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 159 if q, ok := q.(*ent.AppCoinQuery); ok { 160 return f(ctx, q) 161 } 162 return Denyf("ent/privacy: unexpected query type %T, expect *ent.AppCoinQuery", q) 163 } 164 165 // The AppCoinMutationRuleFunc type is an adapter to allow the use of ordinary 166 // functions as a mutation rule. 167 type AppCoinMutationRuleFunc func(context.Context, *ent.AppCoinMutation) error 168 169 // EvalMutation calls f(ctx, m). 170 func (f AppCoinMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 171 if m, ok := m.(*ent.AppCoinMutation); ok { 172 return f(ctx, m) 173 } 174 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.AppCoinMutation", m) 175 } 176 177 // The ChainBaseQueryRuleFunc type is an adapter to allow the use of ordinary 178 // functions as a query rule. 179 type ChainBaseQueryRuleFunc func(context.Context, *ent.ChainBaseQuery) error 180 181 // EvalQuery return f(ctx, q). 182 func (f ChainBaseQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 183 if q, ok := q.(*ent.ChainBaseQuery); ok { 184 return f(ctx, q) 185 } 186 return Denyf("ent/privacy: unexpected query type %T, expect *ent.ChainBaseQuery", q) 187 } 188 189 // The ChainBaseMutationRuleFunc type is an adapter to allow the use of ordinary 190 // functions as a mutation rule. 191 type ChainBaseMutationRuleFunc func(context.Context, *ent.ChainBaseMutation) error 192 193 // EvalMutation calls f(ctx, m). 194 func (f ChainBaseMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 195 if m, ok := m.(*ent.ChainBaseMutation); ok { 196 return f(ctx, m) 197 } 198 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ChainBaseMutation", m) 199 } 200 201 // The CoinBaseQueryRuleFunc type is an adapter to allow the use of ordinary 202 // functions as a query rule. 203 type CoinBaseQueryRuleFunc func(context.Context, *ent.CoinBaseQuery) error 204 205 // EvalQuery return f(ctx, q). 206 func (f CoinBaseQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 207 if q, ok := q.(*ent.CoinBaseQuery); ok { 208 return f(ctx, q) 209 } 210 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinBaseQuery", q) 211 } 212 213 // The CoinBaseMutationRuleFunc type is an adapter to allow the use of ordinary 214 // functions as a mutation rule. 215 type CoinBaseMutationRuleFunc func(context.Context, *ent.CoinBaseMutation) error 216 217 // EvalMutation calls f(ctx, m). 218 func (f CoinBaseMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 219 if m, ok := m.(*ent.CoinBaseMutation); ok { 220 return f(ctx, m) 221 } 222 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinBaseMutation", m) 223 } 224 225 // The CoinDescriptionQueryRuleFunc type is an adapter to allow the use of ordinary 226 // functions as a query rule. 227 type CoinDescriptionQueryRuleFunc func(context.Context, *ent.CoinDescriptionQuery) error 228 229 // EvalQuery return f(ctx, q). 230 func (f CoinDescriptionQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 231 if q, ok := q.(*ent.CoinDescriptionQuery); ok { 232 return f(ctx, q) 233 } 234 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinDescriptionQuery", q) 235 } 236 237 // The CoinDescriptionMutationRuleFunc type is an adapter to allow the use of ordinary 238 // functions as a mutation rule. 239 type CoinDescriptionMutationRuleFunc func(context.Context, *ent.CoinDescriptionMutation) error 240 241 // EvalMutation calls f(ctx, m). 242 func (f CoinDescriptionMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 243 if m, ok := m.(*ent.CoinDescriptionMutation); ok { 244 return f(ctx, m) 245 } 246 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinDescriptionMutation", m) 247 } 248 249 // The CoinExtraQueryRuleFunc type is an adapter to allow the use of ordinary 250 // functions as a query rule. 251 type CoinExtraQueryRuleFunc func(context.Context, *ent.CoinExtraQuery) error 252 253 // EvalQuery return f(ctx, q). 254 func (f CoinExtraQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 255 if q, ok := q.(*ent.CoinExtraQuery); ok { 256 return f(ctx, q) 257 } 258 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinExtraQuery", q) 259 } 260 261 // The CoinExtraMutationRuleFunc type is an adapter to allow the use of ordinary 262 // functions as a mutation rule. 263 type CoinExtraMutationRuleFunc func(context.Context, *ent.CoinExtraMutation) error 264 265 // EvalMutation calls f(ctx, m). 266 func (f CoinExtraMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 267 if m, ok := m.(*ent.CoinExtraMutation); ok { 268 return f(ctx, m) 269 } 270 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinExtraMutation", m) 271 } 272 273 // The CoinFiatQueryRuleFunc type is an adapter to allow the use of ordinary 274 // functions as a query rule. 275 type CoinFiatQueryRuleFunc func(context.Context, *ent.CoinFiatQuery) error 276 277 // EvalQuery return f(ctx, q). 278 func (f CoinFiatQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 279 if q, ok := q.(*ent.CoinFiatQuery); ok { 280 return f(ctx, q) 281 } 282 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinFiatQuery", q) 283 } 284 285 // The CoinFiatMutationRuleFunc type is an adapter to allow the use of ordinary 286 // functions as a mutation rule. 287 type CoinFiatMutationRuleFunc func(context.Context, *ent.CoinFiatMutation) error 288 289 // EvalMutation calls f(ctx, m). 290 func (f CoinFiatMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 291 if m, ok := m.(*ent.CoinFiatMutation); ok { 292 return f(ctx, m) 293 } 294 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinFiatMutation", m) 295 } 296 297 // The CoinFiatCurrencyQueryRuleFunc type is an adapter to allow the use of ordinary 298 // functions as a query rule. 299 type CoinFiatCurrencyQueryRuleFunc func(context.Context, *ent.CoinFiatCurrencyQuery) error 300 301 // EvalQuery return f(ctx, q). 302 func (f CoinFiatCurrencyQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 303 if q, ok := q.(*ent.CoinFiatCurrencyQuery); ok { 304 return f(ctx, q) 305 } 306 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinFiatCurrencyQuery", q) 307 } 308 309 // The CoinFiatCurrencyMutationRuleFunc type is an adapter to allow the use of ordinary 310 // functions as a mutation rule. 311 type CoinFiatCurrencyMutationRuleFunc func(context.Context, *ent.CoinFiatCurrencyMutation) error 312 313 // EvalMutation calls f(ctx, m). 314 func (f CoinFiatCurrencyMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 315 if m, ok := m.(*ent.CoinFiatCurrencyMutation); ok { 316 return f(ctx, m) 317 } 318 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinFiatCurrencyMutation", m) 319 } 320 321 // The CoinFiatCurrencyHistoryQueryRuleFunc type is an adapter to allow the use of ordinary 322 // functions as a query rule. 323 type CoinFiatCurrencyHistoryQueryRuleFunc func(context.Context, *ent.CoinFiatCurrencyHistoryQuery) error 324 325 // EvalQuery return f(ctx, q). 326 func (f CoinFiatCurrencyHistoryQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 327 if q, ok := q.(*ent.CoinFiatCurrencyHistoryQuery); ok { 328 return f(ctx, q) 329 } 330 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinFiatCurrencyHistoryQuery", q) 331 } 332 333 // The CoinFiatCurrencyHistoryMutationRuleFunc type is an adapter to allow the use of ordinary 334 // functions as a mutation rule. 335 type CoinFiatCurrencyHistoryMutationRuleFunc func(context.Context, *ent.CoinFiatCurrencyHistoryMutation) error 336 337 // EvalMutation calls f(ctx, m). 338 func (f CoinFiatCurrencyHistoryMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 339 if m, ok := m.(*ent.CoinFiatCurrencyHistoryMutation); ok { 340 return f(ctx, m) 341 } 342 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinFiatCurrencyHistoryMutation", m) 343 } 344 345 // The CoinUsedForQueryRuleFunc type is an adapter to allow the use of ordinary 346 // functions as a query rule. 347 type CoinUsedForQueryRuleFunc func(context.Context, *ent.CoinUsedForQuery) error 348 349 // EvalQuery return f(ctx, q). 350 func (f CoinUsedForQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 351 if q, ok := q.(*ent.CoinUsedForQuery); ok { 352 return f(ctx, q) 353 } 354 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CoinUsedForQuery", q) 355 } 356 357 // The CoinUsedForMutationRuleFunc type is an adapter to allow the use of ordinary 358 // functions as a mutation rule. 359 type CoinUsedForMutationRuleFunc func(context.Context, *ent.CoinUsedForMutation) error 360 361 // EvalMutation calls f(ctx, m). 362 func (f CoinUsedForMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 363 if m, ok := m.(*ent.CoinUsedForMutation); ok { 364 return f(ctx, m) 365 } 366 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CoinUsedForMutation", m) 367 } 368 369 // The CurrencyQueryRuleFunc type is an adapter to allow the use of ordinary 370 // functions as a query rule. 371 type CurrencyQueryRuleFunc func(context.Context, *ent.CurrencyQuery) error 372 373 // EvalQuery return f(ctx, q). 374 func (f CurrencyQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 375 if q, ok := q.(*ent.CurrencyQuery); ok { 376 return f(ctx, q) 377 } 378 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CurrencyQuery", q) 379 } 380 381 // The CurrencyMutationRuleFunc type is an adapter to allow the use of ordinary 382 // functions as a mutation rule. 383 type CurrencyMutationRuleFunc func(context.Context, *ent.CurrencyMutation) error 384 385 // EvalMutation calls f(ctx, m). 386 func (f CurrencyMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 387 if m, ok := m.(*ent.CurrencyMutation); ok { 388 return f(ctx, m) 389 } 390 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CurrencyMutation", m) 391 } 392 393 // The CurrencyFeedQueryRuleFunc type is an adapter to allow the use of ordinary 394 // functions as a query rule. 395 type CurrencyFeedQueryRuleFunc func(context.Context, *ent.CurrencyFeedQuery) error 396 397 // EvalQuery return f(ctx, q). 398 func (f CurrencyFeedQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 399 if q, ok := q.(*ent.CurrencyFeedQuery); ok { 400 return f(ctx, q) 401 } 402 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CurrencyFeedQuery", q) 403 } 404 405 // The CurrencyFeedMutationRuleFunc type is an adapter to allow the use of ordinary 406 // functions as a mutation rule. 407 type CurrencyFeedMutationRuleFunc func(context.Context, *ent.CurrencyFeedMutation) error 408 409 // EvalMutation calls f(ctx, m). 410 func (f CurrencyFeedMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 411 if m, ok := m.(*ent.CurrencyFeedMutation); ok { 412 return f(ctx, m) 413 } 414 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CurrencyFeedMutation", m) 415 } 416 417 // The CurrencyHistoryQueryRuleFunc type is an adapter to allow the use of ordinary 418 // functions as a query rule. 419 type CurrencyHistoryQueryRuleFunc func(context.Context, *ent.CurrencyHistoryQuery) error 420 421 // EvalQuery return f(ctx, q). 422 func (f CurrencyHistoryQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 423 if q, ok := q.(*ent.CurrencyHistoryQuery); ok { 424 return f(ctx, q) 425 } 426 return Denyf("ent/privacy: unexpected query type %T, expect *ent.CurrencyHistoryQuery", q) 427 } 428 429 // The CurrencyHistoryMutationRuleFunc type is an adapter to allow the use of ordinary 430 // functions as a mutation rule. 431 type CurrencyHistoryMutationRuleFunc func(context.Context, *ent.CurrencyHistoryMutation) error 432 433 // EvalMutation calls f(ctx, m). 434 func (f CurrencyHistoryMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 435 if m, ok := m.(*ent.CurrencyHistoryMutation); ok { 436 return f(ctx, m) 437 } 438 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CurrencyHistoryMutation", m) 439 } 440 441 // The ExchangeRateQueryRuleFunc type is an adapter to allow the use of ordinary 442 // functions as a query rule. 443 type ExchangeRateQueryRuleFunc func(context.Context, *ent.ExchangeRateQuery) error 444 445 // EvalQuery return f(ctx, q). 446 func (f ExchangeRateQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 447 if q, ok := q.(*ent.ExchangeRateQuery); ok { 448 return f(ctx, q) 449 } 450 return Denyf("ent/privacy: unexpected query type %T, expect *ent.ExchangeRateQuery", q) 451 } 452 453 // The ExchangeRateMutationRuleFunc type is an adapter to allow the use of ordinary 454 // functions as a mutation rule. 455 type ExchangeRateMutationRuleFunc func(context.Context, *ent.ExchangeRateMutation) error 456 457 // EvalMutation calls f(ctx, m). 458 func (f ExchangeRateMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 459 if m, ok := m.(*ent.ExchangeRateMutation); ok { 460 return f(ctx, m) 461 } 462 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ExchangeRateMutation", m) 463 } 464 465 // The FiatQueryRuleFunc type is an adapter to allow the use of ordinary 466 // functions as a query rule. 467 type FiatQueryRuleFunc func(context.Context, *ent.FiatQuery) error 468 469 // EvalQuery return f(ctx, q). 470 func (f FiatQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 471 if q, ok := q.(*ent.FiatQuery); ok { 472 return f(ctx, q) 473 } 474 return Denyf("ent/privacy: unexpected query type %T, expect *ent.FiatQuery", q) 475 } 476 477 // The FiatMutationRuleFunc type is an adapter to allow the use of ordinary 478 // functions as a mutation rule. 479 type FiatMutationRuleFunc func(context.Context, *ent.FiatMutation) error 480 481 // EvalMutation calls f(ctx, m). 482 func (f FiatMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 483 if m, ok := m.(*ent.FiatMutation); ok { 484 return f(ctx, m) 485 } 486 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FiatMutation", m) 487 } 488 489 // The FiatCurrencyQueryRuleFunc type is an adapter to allow the use of ordinary 490 // functions as a query rule. 491 type FiatCurrencyQueryRuleFunc func(context.Context, *ent.FiatCurrencyQuery) error 492 493 // EvalQuery return f(ctx, q). 494 func (f FiatCurrencyQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 495 if q, ok := q.(*ent.FiatCurrencyQuery); ok { 496 return f(ctx, q) 497 } 498 return Denyf("ent/privacy: unexpected query type %T, expect *ent.FiatCurrencyQuery", q) 499 } 500 501 // The FiatCurrencyMutationRuleFunc type is an adapter to allow the use of ordinary 502 // functions as a mutation rule. 503 type FiatCurrencyMutationRuleFunc func(context.Context, *ent.FiatCurrencyMutation) error 504 505 // EvalMutation calls f(ctx, m). 506 func (f FiatCurrencyMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 507 if m, ok := m.(*ent.FiatCurrencyMutation); ok { 508 return f(ctx, m) 509 } 510 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FiatCurrencyMutation", m) 511 } 512 513 // The FiatCurrencyFeedQueryRuleFunc type is an adapter to allow the use of ordinary 514 // functions as a query rule. 515 type FiatCurrencyFeedQueryRuleFunc func(context.Context, *ent.FiatCurrencyFeedQuery) error 516 517 // EvalQuery return f(ctx, q). 518 func (f FiatCurrencyFeedQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 519 if q, ok := q.(*ent.FiatCurrencyFeedQuery); ok { 520 return f(ctx, q) 521 } 522 return Denyf("ent/privacy: unexpected query type %T, expect *ent.FiatCurrencyFeedQuery", q) 523 } 524 525 // The FiatCurrencyFeedMutationRuleFunc type is an adapter to allow the use of ordinary 526 // functions as a mutation rule. 527 type FiatCurrencyFeedMutationRuleFunc func(context.Context, *ent.FiatCurrencyFeedMutation) error 528 529 // EvalMutation calls f(ctx, m). 530 func (f FiatCurrencyFeedMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 531 if m, ok := m.(*ent.FiatCurrencyFeedMutation); ok { 532 return f(ctx, m) 533 } 534 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FiatCurrencyFeedMutation", m) 535 } 536 537 // The FiatCurrencyHistoryQueryRuleFunc type is an adapter to allow the use of ordinary 538 // functions as a query rule. 539 type FiatCurrencyHistoryQueryRuleFunc func(context.Context, *ent.FiatCurrencyHistoryQuery) error 540 541 // EvalQuery return f(ctx, q). 542 func (f FiatCurrencyHistoryQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 543 if q, ok := q.(*ent.FiatCurrencyHistoryQuery); ok { 544 return f(ctx, q) 545 } 546 return Denyf("ent/privacy: unexpected query type %T, expect *ent.FiatCurrencyHistoryQuery", q) 547 } 548 549 // The FiatCurrencyHistoryMutationRuleFunc type is an adapter to allow the use of ordinary 550 // functions as a mutation rule. 551 type FiatCurrencyHistoryMutationRuleFunc func(context.Context, *ent.FiatCurrencyHistoryMutation) error 552 553 // EvalMutation calls f(ctx, m). 554 func (f FiatCurrencyHistoryMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 555 if m, ok := m.(*ent.FiatCurrencyHistoryMutation); ok { 556 return f(ctx, m) 557 } 558 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FiatCurrencyHistoryMutation", m) 559 } 560 561 // The SettingQueryRuleFunc type is an adapter to allow the use of ordinary 562 // functions as a query rule. 563 type SettingQueryRuleFunc func(context.Context, *ent.SettingQuery) error 564 565 // EvalQuery return f(ctx, q). 566 func (f SettingQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 567 if q, ok := q.(*ent.SettingQuery); ok { 568 return f(ctx, q) 569 } 570 return Denyf("ent/privacy: unexpected query type %T, expect *ent.SettingQuery", q) 571 } 572 573 // The SettingMutationRuleFunc type is an adapter to allow the use of ordinary 574 // functions as a mutation rule. 575 type SettingMutationRuleFunc func(context.Context, *ent.SettingMutation) error 576 577 // EvalMutation calls f(ctx, m). 578 func (f SettingMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 579 if m, ok := m.(*ent.SettingMutation); ok { 580 return f(ctx, m) 581 } 582 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SettingMutation", m) 583 } 584 585 // The TranQueryRuleFunc type is an adapter to allow the use of ordinary 586 // functions as a query rule. 587 type TranQueryRuleFunc func(context.Context, *ent.TranQuery) error 588 589 // EvalQuery return f(ctx, q). 590 func (f TranQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { 591 if q, ok := q.(*ent.TranQuery); ok { 592 return f(ctx, q) 593 } 594 return Denyf("ent/privacy: unexpected query type %T, expect *ent.TranQuery", q) 595 } 596 597 // The TranMutationRuleFunc type is an adapter to allow the use of ordinary 598 // functions as a mutation rule. 599 type TranMutationRuleFunc func(context.Context, *ent.TranMutation) error 600 601 // EvalMutation calls f(ctx, m). 602 func (f TranMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 603 if m, ok := m.(*ent.TranMutation); ok { 604 return f(ctx, m) 605 } 606 return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.TranMutation", m) 607 } 608 609 type ( 610 // Filter is the interface that wraps the Where function 611 // for filtering nodes in queries and mutations. 612 Filter interface { 613 // Where applies a filter on the executed query/mutation. 614 Where(entql.P) 615 } 616 617 // The FilterFunc type is an adapter that allows the use of ordinary 618 // functions as filters for query and mutation types. 619 FilterFunc func(context.Context, Filter) error 620 ) 621 622 // EvalQuery calls f(ctx, q) if the query implements the Filter interface, otherwise it is denied. 623 func (f FilterFunc) EvalQuery(ctx context.Context, q ent.Query) error { 624 fr, err := queryFilter(q) 625 if err != nil { 626 return err 627 } 628 return f(ctx, fr) 629 } 630 631 // EvalMutation calls f(ctx, q) if the mutation implements the Filter interface, otherwise it is denied. 632 func (f FilterFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { 633 fr, err := mutationFilter(m) 634 if err != nil { 635 return err 636 } 637 return f(ctx, fr) 638 } 639 640 var _ QueryMutationRule = FilterFunc(nil) 641 642 func queryFilter(q ent.Query) (Filter, error) { 643 switch q := q.(type) { 644 case *ent.AppCoinQuery: 645 return q.Filter(), nil 646 case *ent.ChainBaseQuery: 647 return q.Filter(), nil 648 case *ent.CoinBaseQuery: 649 return q.Filter(), nil 650 case *ent.CoinDescriptionQuery: 651 return q.Filter(), nil 652 case *ent.CoinExtraQuery: 653 return q.Filter(), nil 654 case *ent.CoinFiatQuery: 655 return q.Filter(), nil 656 case *ent.CoinFiatCurrencyQuery: 657 return q.Filter(), nil 658 case *ent.CoinFiatCurrencyHistoryQuery: 659 return q.Filter(), nil 660 case *ent.CoinUsedForQuery: 661 return q.Filter(), nil 662 case *ent.CurrencyQuery: 663 return q.Filter(), nil 664 case *ent.CurrencyFeedQuery: 665 return q.Filter(), nil 666 case *ent.CurrencyHistoryQuery: 667 return q.Filter(), nil 668 case *ent.ExchangeRateQuery: 669 return q.Filter(), nil 670 case *ent.FiatQuery: 671 return q.Filter(), nil 672 case *ent.FiatCurrencyQuery: 673 return q.Filter(), nil 674 case *ent.FiatCurrencyFeedQuery: 675 return q.Filter(), nil 676 case *ent.FiatCurrencyHistoryQuery: 677 return q.Filter(), nil 678 case *ent.SettingQuery: 679 return q.Filter(), nil 680 case *ent.TranQuery: 681 return q.Filter(), nil 682 default: 683 return nil, Denyf("ent/privacy: unexpected query type %T for query filter", q) 684 } 685 } 686 687 func mutationFilter(m ent.Mutation) (Filter, error) { 688 switch m := m.(type) { 689 case *ent.AppCoinMutation: 690 return m.Filter(), nil 691 case *ent.ChainBaseMutation: 692 return m.Filter(), nil 693 case *ent.CoinBaseMutation: 694 return m.Filter(), nil 695 case *ent.CoinDescriptionMutation: 696 return m.Filter(), nil 697 case *ent.CoinExtraMutation: 698 return m.Filter(), nil 699 case *ent.CoinFiatMutation: 700 return m.Filter(), nil 701 case *ent.CoinFiatCurrencyMutation: 702 return m.Filter(), nil 703 case *ent.CoinFiatCurrencyHistoryMutation: 704 return m.Filter(), nil 705 case *ent.CoinUsedForMutation: 706 return m.Filter(), nil 707 case *ent.CurrencyMutation: 708 return m.Filter(), nil 709 case *ent.CurrencyFeedMutation: 710 return m.Filter(), nil 711 case *ent.CurrencyHistoryMutation: 712 return m.Filter(), nil 713 case *ent.ExchangeRateMutation: 714 return m.Filter(), nil 715 case *ent.FiatMutation: 716 return m.Filter(), nil 717 case *ent.FiatCurrencyMutation: 718 return m.Filter(), nil 719 case *ent.FiatCurrencyFeedMutation: 720 return m.Filter(), nil 721 case *ent.FiatCurrencyHistoryMutation: 722 return m.Filter(), nil 723 case *ent.SettingMutation: 724 return m.Filter(), nil 725 case *ent.TranMutation: 726 return m.Filter(), nil 727 default: 728 return nil, Denyf("ent/privacy: unexpected mutation type %T for mutation filter", m) 729 } 730 }