hook.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. // Code generated by ent, DO NOT EDIT.
  2. package hook
  3. import (
  4. "context"
  5. "fmt"
  6. "wechat-api/ent"
  7. )
  8. // The AgentFunc type is an adapter to allow the use of ordinary
  9. // function as Agent mutator.
  10. type AgentFunc func(context.Context, *ent.AgentMutation) (ent.Value, error)
  11. // Mutate calls f(ctx, m).
  12. func (f AgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  13. if mv, ok := m.(*ent.AgentMutation); ok {
  14. return f(ctx, mv)
  15. }
  16. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgentMutation", m)
  17. }
  18. // The AgentBaseFunc type is an adapter to allow the use of ordinary
  19. // function as AgentBase mutator.
  20. type AgentBaseFunc func(context.Context, *ent.AgentBaseMutation) (ent.Value, error)
  21. // Mutate calls f(ctx, m).
  22. func (f AgentBaseFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  23. if mv, ok := m.(*ent.AgentBaseMutation); ok {
  24. return f(ctx, mv)
  25. }
  26. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgentBaseMutation", m)
  27. }
  28. // The AliyunAvatarFunc type is an adapter to allow the use of ordinary
  29. // function as AliyunAvatar mutator.
  30. type AliyunAvatarFunc func(context.Context, *ent.AliyunAvatarMutation) (ent.Value, error)
  31. // Mutate calls f(ctx, m).
  32. func (f AliyunAvatarFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  33. if mv, ok := m.(*ent.AliyunAvatarMutation); ok {
  34. return f(ctx, mv)
  35. }
  36. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AliyunAvatarMutation", m)
  37. }
  38. // The AllocAgentFunc type is an adapter to allow the use of ordinary
  39. // function as AllocAgent mutator.
  40. type AllocAgentFunc func(context.Context, *ent.AllocAgentMutation) (ent.Value, error)
  41. // Mutate calls f(ctx, m).
  42. func (f AllocAgentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  43. if mv, ok := m.(*ent.AllocAgentMutation); ok {
  44. return f(ctx, mv)
  45. }
  46. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AllocAgentMutation", m)
  47. }
  48. // The ApiKeyFunc type is an adapter to allow the use of ordinary
  49. // function as ApiKey mutator.
  50. type ApiKeyFunc func(context.Context, *ent.ApiKeyMutation) (ent.Value, error)
  51. // Mutate calls f(ctx, m).
  52. func (f ApiKeyFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  53. if mv, ok := m.(*ent.ApiKeyMutation); ok {
  54. return f(ctx, mv)
  55. }
  56. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ApiKeyMutation", m)
  57. }
  58. // The BatchMsgFunc type is an adapter to allow the use of ordinary
  59. // function as BatchMsg mutator.
  60. type BatchMsgFunc func(context.Context, *ent.BatchMsgMutation) (ent.Value, error)
  61. // Mutate calls f(ctx, m).
  62. func (f BatchMsgFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  63. if mv, ok := m.(*ent.BatchMsgMutation); ok {
  64. return f(ctx, mv)
  65. }
  66. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.BatchMsgMutation", m)
  67. }
  68. // The CategoryFunc type is an adapter to allow the use of ordinary
  69. // function as Category mutator.
  70. type CategoryFunc func(context.Context, *ent.CategoryMutation) (ent.Value, error)
  71. // Mutate calls f(ctx, m).
  72. func (f CategoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  73. if mv, ok := m.(*ent.CategoryMutation); ok {
  74. return f(ctx, mv)
  75. }
  76. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CategoryMutation", m)
  77. }
  78. // The ChatRecordsFunc type is an adapter to allow the use of ordinary
  79. // function as ChatRecords mutator.
  80. type ChatRecordsFunc func(context.Context, *ent.ChatRecordsMutation) (ent.Value, error)
  81. // Mutate calls f(ctx, m).
  82. func (f ChatRecordsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  83. if mv, ok := m.(*ent.ChatRecordsMutation); ok {
  84. return f(ctx, mv)
  85. }
  86. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChatRecordsMutation", m)
  87. }
  88. // The ChatSessionFunc type is an adapter to allow the use of ordinary
  89. // function as ChatSession mutator.
  90. type ChatSessionFunc func(context.Context, *ent.ChatSessionMutation) (ent.Value, error)
  91. // Mutate calls f(ctx, m).
  92. func (f ChatSessionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  93. if mv, ok := m.(*ent.ChatSessionMutation); ok {
  94. return f(ctx, mv)
  95. }
  96. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChatSessionMutation", m)
  97. }
  98. // The CompapiAsynctaskFunc type is an adapter to allow the use of ordinary
  99. // function as CompapiAsynctask mutator.
  100. type CompapiAsynctaskFunc func(context.Context, *ent.CompapiAsynctaskMutation) (ent.Value, error)
  101. // Mutate calls f(ctx, m).
  102. func (f CompapiAsynctaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  103. if mv, ok := m.(*ent.CompapiAsynctaskMutation); ok {
  104. return f(ctx, mv)
  105. }
  106. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CompapiAsynctaskMutation", m)
  107. }
  108. // The ContactFunc type is an adapter to allow the use of ordinary
  109. // function as Contact mutator.
  110. type ContactFunc func(context.Context, *ent.ContactMutation) (ent.Value, error)
  111. // Mutate calls f(ctx, m).
  112. func (f ContactFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  113. if mv, ok := m.(*ent.ContactMutation); ok {
  114. return f(ctx, mv)
  115. }
  116. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ContactMutation", m)
  117. }
  118. // The ContactFieldFunc type is an adapter to allow the use of ordinary
  119. // function as ContactField mutator.
  120. type ContactFieldFunc func(context.Context, *ent.ContactFieldMutation) (ent.Value, error)
  121. // Mutate calls f(ctx, m).
  122. func (f ContactFieldFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  123. if mv, ok := m.(*ent.ContactFieldMutation); ok {
  124. return f(ctx, mv)
  125. }
  126. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ContactFieldMutation", m)
  127. }
  128. // The ContactFieldTemplateFunc type is an adapter to allow the use of ordinary
  129. // function as ContactFieldTemplate mutator.
  130. type ContactFieldTemplateFunc func(context.Context, *ent.ContactFieldTemplateMutation) (ent.Value, error)
  131. // Mutate calls f(ctx, m).
  132. func (f ContactFieldTemplateFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  133. if mv, ok := m.(*ent.ContactFieldTemplateMutation); ok {
  134. return f(ctx, mv)
  135. }
  136. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ContactFieldTemplateMutation", m)
  137. }
  138. // The CreditBalanceFunc type is an adapter to allow the use of ordinary
  139. // function as CreditBalance mutator.
  140. type CreditBalanceFunc func(context.Context, *ent.CreditBalanceMutation) (ent.Value, error)
  141. // Mutate calls f(ctx, m).
  142. func (f CreditBalanceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  143. if mv, ok := m.(*ent.CreditBalanceMutation); ok {
  144. return f(ctx, mv)
  145. }
  146. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CreditBalanceMutation", m)
  147. }
  148. // The CreditUsageFunc type is an adapter to allow the use of ordinary
  149. // function as CreditUsage mutator.
  150. type CreditUsageFunc func(context.Context, *ent.CreditUsageMutation) (ent.Value, error)
  151. // Mutate calls f(ctx, m).
  152. func (f CreditUsageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  153. if mv, ok := m.(*ent.CreditUsageMutation); ok {
  154. return f(ctx, mv)
  155. }
  156. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CreditUsageMutation", m)
  157. }
  158. // The EmployeeFunc type is an adapter to allow the use of ordinary
  159. // function as Employee mutator.
  160. type EmployeeFunc func(context.Context, *ent.EmployeeMutation) (ent.Value, error)
  161. // Mutate calls f(ctx, m).
  162. func (f EmployeeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  163. if mv, ok := m.(*ent.EmployeeMutation); ok {
  164. return f(ctx, mv)
  165. }
  166. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EmployeeMutation", m)
  167. }
  168. // The EmployeeConfigFunc type is an adapter to allow the use of ordinary
  169. // function as EmployeeConfig mutator.
  170. type EmployeeConfigFunc func(context.Context, *ent.EmployeeConfigMutation) (ent.Value, error)
  171. // Mutate calls f(ctx, m).
  172. func (f EmployeeConfigFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  173. if mv, ok := m.(*ent.EmployeeConfigMutation); ok {
  174. return f(ctx, mv)
  175. }
  176. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EmployeeConfigMutation", m)
  177. }
  178. // The LabelFunc type is an adapter to allow the use of ordinary
  179. // function as Label mutator.
  180. type LabelFunc func(context.Context, *ent.LabelMutation) (ent.Value, error)
  181. // Mutate calls f(ctx, m).
  182. func (f LabelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  183. if mv, ok := m.(*ent.LabelMutation); ok {
  184. return f(ctx, mv)
  185. }
  186. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelMutation", m)
  187. }
  188. // The LabelLogFunc type is an adapter to allow the use of ordinary
  189. // function as LabelLog mutator.
  190. type LabelLogFunc func(context.Context, *ent.LabelLogMutation) (ent.Value, error)
  191. // Mutate calls f(ctx, m).
  192. func (f LabelLogFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  193. if mv, ok := m.(*ent.LabelLogMutation); ok {
  194. return f(ctx, mv)
  195. }
  196. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelLogMutation", m)
  197. }
  198. // The LabelRelationshipFunc type is an adapter to allow the use of ordinary
  199. // function as LabelRelationship mutator.
  200. type LabelRelationshipFunc func(context.Context, *ent.LabelRelationshipMutation) (ent.Value, error)
  201. // Mutate calls f(ctx, m).
  202. func (f LabelRelationshipFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  203. if mv, ok := m.(*ent.LabelRelationshipMutation); ok {
  204. return f(ctx, mv)
  205. }
  206. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelRelationshipMutation", m)
  207. }
  208. // The LabelTaggingFunc type is an adapter to allow the use of ordinary
  209. // function as LabelTagging mutator.
  210. type LabelTaggingFunc func(context.Context, *ent.LabelTaggingMutation) (ent.Value, error)
  211. // Mutate calls f(ctx, m).
  212. func (f LabelTaggingFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  213. if mv, ok := m.(*ent.LabelTaggingMutation); ok {
  214. return f(ctx, mv)
  215. }
  216. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LabelTaggingMutation", m)
  217. }
  218. // The MessageFunc type is an adapter to allow the use of ordinary
  219. // function as Message mutator.
  220. type MessageFunc func(context.Context, *ent.MessageMutation) (ent.Value, error)
  221. // Mutate calls f(ctx, m).
  222. func (f MessageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  223. if mv, ok := m.(*ent.MessageMutation); ok {
  224. return f(ctx, mv)
  225. }
  226. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MessageMutation", m)
  227. }
  228. // The MessageRecordsFunc type is an adapter to allow the use of ordinary
  229. // function as MessageRecords mutator.
  230. type MessageRecordsFunc func(context.Context, *ent.MessageRecordsMutation) (ent.Value, error)
  231. // Mutate calls f(ctx, m).
  232. func (f MessageRecordsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  233. if mv, ok := m.(*ent.MessageRecordsMutation); ok {
  234. return f(ctx, mv)
  235. }
  236. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MessageRecordsMutation", m)
  237. }
  238. // The MsgFunc type is an adapter to allow the use of ordinary
  239. // function as Msg mutator.
  240. type MsgFunc func(context.Context, *ent.MsgMutation) (ent.Value, error)
  241. // Mutate calls f(ctx, m).
  242. func (f MsgFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  243. if mv, ok := m.(*ent.MsgMutation); ok {
  244. return f(ctx, mv)
  245. }
  246. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MsgMutation", m)
  247. }
  248. // The PayRechargeFunc type is an adapter to allow the use of ordinary
  249. // function as PayRecharge mutator.
  250. type PayRechargeFunc func(context.Context, *ent.PayRechargeMutation) (ent.Value, error)
  251. // Mutate calls f(ctx, m).
  252. func (f PayRechargeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  253. if mv, ok := m.(*ent.PayRechargeMutation); ok {
  254. return f(ctx, mv)
  255. }
  256. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PayRechargeMutation", m)
  257. }
  258. // The ServerFunc type is an adapter to allow the use of ordinary
  259. // function as Server mutator.
  260. type ServerFunc func(context.Context, *ent.ServerMutation) (ent.Value, error)
  261. // Mutate calls f(ctx, m).
  262. func (f ServerFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  263. if mv, ok := m.(*ent.ServerMutation); ok {
  264. return f(ctx, mv)
  265. }
  266. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ServerMutation", m)
  267. }
  268. // The SopNodeFunc type is an adapter to allow the use of ordinary
  269. // function as SopNode mutator.
  270. type SopNodeFunc func(context.Context, *ent.SopNodeMutation) (ent.Value, error)
  271. // Mutate calls f(ctx, m).
  272. func (f SopNodeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  273. if mv, ok := m.(*ent.SopNodeMutation); ok {
  274. return f(ctx, mv)
  275. }
  276. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SopNodeMutation", m)
  277. }
  278. // The SopStageFunc type is an adapter to allow the use of ordinary
  279. // function as SopStage mutator.
  280. type SopStageFunc func(context.Context, *ent.SopStageMutation) (ent.Value, error)
  281. // Mutate calls f(ctx, m).
  282. func (f SopStageFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  283. if mv, ok := m.(*ent.SopStageMutation); ok {
  284. return f(ctx, mv)
  285. }
  286. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SopStageMutation", m)
  287. }
  288. // The SopTaskFunc type is an adapter to allow the use of ordinary
  289. // function as SopTask mutator.
  290. type SopTaskFunc func(context.Context, *ent.SopTaskMutation) (ent.Value, error)
  291. // Mutate calls f(ctx, m).
  292. func (f SopTaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  293. if mv, ok := m.(*ent.SopTaskMutation); ok {
  294. return f(ctx, mv)
  295. }
  296. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SopTaskMutation", m)
  297. }
  298. // The TokenFunc type is an adapter to allow the use of ordinary
  299. // function as Token mutator.
  300. type TokenFunc func(context.Context, *ent.TokenMutation) (ent.Value, error)
  301. // Mutate calls f(ctx, m).
  302. func (f TokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  303. if mv, ok := m.(*ent.TokenMutation); ok {
  304. return f(ctx, mv)
  305. }
  306. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TokenMutation", m)
  307. }
  308. // The TutorialFunc type is an adapter to allow the use of ordinary
  309. // function as Tutorial mutator.
  310. type TutorialFunc func(context.Context, *ent.TutorialMutation) (ent.Value, error)
  311. // Mutate calls f(ctx, m).
  312. func (f TutorialFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  313. if mv, ok := m.(*ent.TutorialMutation); ok {
  314. return f(ctx, mv)
  315. }
  316. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TutorialMutation", m)
  317. }
  318. // The UsageDetailFunc type is an adapter to allow the use of ordinary
  319. // function as UsageDetail mutator.
  320. type UsageDetailFunc func(context.Context, *ent.UsageDetailMutation) (ent.Value, error)
  321. // Mutate calls f(ctx, m).
  322. func (f UsageDetailFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  323. if mv, ok := m.(*ent.UsageDetailMutation); ok {
  324. return f(ctx, mv)
  325. }
  326. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageDetailMutation", m)
  327. }
  328. // The UsageStatisticDayFunc type is an adapter to allow the use of ordinary
  329. // function as UsageStatisticDay mutator.
  330. type UsageStatisticDayFunc func(context.Context, *ent.UsageStatisticDayMutation) (ent.Value, error)
  331. // Mutate calls f(ctx, m).
  332. func (f UsageStatisticDayFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  333. if mv, ok := m.(*ent.UsageStatisticDayMutation); ok {
  334. return f(ctx, mv)
  335. }
  336. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageStatisticDayMutation", m)
  337. }
  338. // The UsageStatisticHourFunc type is an adapter to allow the use of ordinary
  339. // function as UsageStatisticHour mutator.
  340. type UsageStatisticHourFunc func(context.Context, *ent.UsageStatisticHourMutation) (ent.Value, error)
  341. // Mutate calls f(ctx, m).
  342. func (f UsageStatisticHourFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  343. if mv, ok := m.(*ent.UsageStatisticHourMutation); ok {
  344. return f(ctx, mv)
  345. }
  346. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageStatisticHourMutation", m)
  347. }
  348. // The UsageStatisticMonthFunc type is an adapter to allow the use of ordinary
  349. // function as UsageStatisticMonth mutator.
  350. type UsageStatisticMonthFunc func(context.Context, *ent.UsageStatisticMonthMutation) (ent.Value, error)
  351. // Mutate calls f(ctx, m).
  352. func (f UsageStatisticMonthFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  353. if mv, ok := m.(*ent.UsageStatisticMonthMutation); ok {
  354. return f(ctx, mv)
  355. }
  356. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageStatisticMonthMutation", m)
  357. }
  358. // The UsageTotalFunc type is an adapter to allow the use of ordinary
  359. // function as UsageTotal mutator.
  360. type UsageTotalFunc func(context.Context, *ent.UsageTotalMutation) (ent.Value, error)
  361. // Mutate calls f(ctx, m).
  362. func (f UsageTotalFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  363. if mv, ok := m.(*ent.UsageTotalMutation); ok {
  364. return f(ctx, mv)
  365. }
  366. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UsageTotalMutation", m)
  367. }
  368. // The WhatsappFunc type is an adapter to allow the use of ordinary
  369. // function as Whatsapp mutator.
  370. type WhatsappFunc func(context.Context, *ent.WhatsappMutation) (ent.Value, error)
  371. // Mutate calls f(ctx, m).
  372. func (f WhatsappFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  373. if mv, ok := m.(*ent.WhatsappMutation); ok {
  374. return f(ctx, mv)
  375. }
  376. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WhatsappMutation", m)
  377. }
  378. // The WhatsappChannelFunc type is an adapter to allow the use of ordinary
  379. // function as WhatsappChannel mutator.
  380. type WhatsappChannelFunc func(context.Context, *ent.WhatsappChannelMutation) (ent.Value, error)
  381. // Mutate calls f(ctx, m).
  382. func (f WhatsappChannelFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  383. if mv, ok := m.(*ent.WhatsappChannelMutation); ok {
  384. return f(ctx, mv)
  385. }
  386. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WhatsappChannelMutation", m)
  387. }
  388. // The WorkExperienceFunc type is an adapter to allow the use of ordinary
  389. // function as WorkExperience mutator.
  390. type WorkExperienceFunc func(context.Context, *ent.WorkExperienceMutation) (ent.Value, error)
  391. // Mutate calls f(ctx, m).
  392. func (f WorkExperienceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  393. if mv, ok := m.(*ent.WorkExperienceMutation); ok {
  394. return f(ctx, mv)
  395. }
  396. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WorkExperienceMutation", m)
  397. }
  398. // The WpChatroomFunc type is an adapter to allow the use of ordinary
  399. // function as WpChatroom mutator.
  400. type WpChatroomFunc func(context.Context, *ent.WpChatroomMutation) (ent.Value, error)
  401. // Mutate calls f(ctx, m).
  402. func (f WpChatroomFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  403. if mv, ok := m.(*ent.WpChatroomMutation); ok {
  404. return f(ctx, mv)
  405. }
  406. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WpChatroomMutation", m)
  407. }
  408. // The WpChatroomMemberFunc type is an adapter to allow the use of ordinary
  409. // function as WpChatroomMember mutator.
  410. type WpChatroomMemberFunc func(context.Context, *ent.WpChatroomMemberMutation) (ent.Value, error)
  411. // Mutate calls f(ctx, m).
  412. func (f WpChatroomMemberFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  413. if mv, ok := m.(*ent.WpChatroomMemberMutation); ok {
  414. return f(ctx, mv)
  415. }
  416. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WpChatroomMemberMutation", m)
  417. }
  418. // The WxFunc type is an adapter to allow the use of ordinary
  419. // function as Wx mutator.
  420. type WxFunc func(context.Context, *ent.WxMutation) (ent.Value, error)
  421. // Mutate calls f(ctx, m).
  422. func (f WxFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  423. if mv, ok := m.(*ent.WxMutation); ok {
  424. return f(ctx, mv)
  425. }
  426. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxMutation", m)
  427. }
  428. // The WxCardFunc type is an adapter to allow the use of ordinary
  429. // function as WxCard mutator.
  430. type WxCardFunc func(context.Context, *ent.WxCardMutation) (ent.Value, error)
  431. // Mutate calls f(ctx, m).
  432. func (f WxCardFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  433. if mv, ok := m.(*ent.WxCardMutation); ok {
  434. return f(ctx, mv)
  435. }
  436. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxCardMutation", m)
  437. }
  438. // The WxCardUserFunc type is an adapter to allow the use of ordinary
  439. // function as WxCardUser mutator.
  440. type WxCardUserFunc func(context.Context, *ent.WxCardUserMutation) (ent.Value, error)
  441. // Mutate calls f(ctx, m).
  442. func (f WxCardUserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  443. if mv, ok := m.(*ent.WxCardUserMutation); ok {
  444. return f(ctx, mv)
  445. }
  446. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxCardUserMutation", m)
  447. }
  448. // The WxCardVisitFunc type is an adapter to allow the use of ordinary
  449. // function as WxCardVisit mutator.
  450. type WxCardVisitFunc func(context.Context, *ent.WxCardVisitMutation) (ent.Value, error)
  451. // Mutate calls f(ctx, m).
  452. func (f WxCardVisitFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  453. if mv, ok := m.(*ent.WxCardVisitMutation); ok {
  454. return f(ctx, mv)
  455. }
  456. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WxCardVisitMutation", m)
  457. }
  458. // The XunjiFunc type is an adapter to allow the use of ordinary
  459. // function as Xunji mutator.
  460. type XunjiFunc func(context.Context, *ent.XunjiMutation) (ent.Value, error)
  461. // Mutate calls f(ctx, m).
  462. func (f XunjiFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  463. if mv, ok := m.(*ent.XunjiMutation); ok {
  464. return f(ctx, mv)
  465. }
  466. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.XunjiMutation", m)
  467. }
  468. // The XunjiServiceFunc type is an adapter to allow the use of ordinary
  469. // function as XunjiService mutator.
  470. type XunjiServiceFunc func(context.Context, *ent.XunjiServiceMutation) (ent.Value, error)
  471. // Mutate calls f(ctx, m).
  472. func (f XunjiServiceFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  473. if mv, ok := m.(*ent.XunjiServiceMutation); ok {
  474. return f(ctx, mv)
  475. }
  476. return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.XunjiServiceMutation", m)
  477. }
  478. // Condition is a hook condition function.
  479. type Condition func(context.Context, ent.Mutation) bool
  480. // And groups conditions with the AND operator.
  481. func And(first, second Condition, rest ...Condition) Condition {
  482. return func(ctx context.Context, m ent.Mutation) bool {
  483. if !first(ctx, m) || !second(ctx, m) {
  484. return false
  485. }
  486. for _, cond := range rest {
  487. if !cond(ctx, m) {
  488. return false
  489. }
  490. }
  491. return true
  492. }
  493. }
  494. // Or groups conditions with the OR operator.
  495. func Or(first, second Condition, rest ...Condition) Condition {
  496. return func(ctx context.Context, m ent.Mutation) bool {
  497. if first(ctx, m) || second(ctx, m) {
  498. return true
  499. }
  500. for _, cond := range rest {
  501. if cond(ctx, m) {
  502. return true
  503. }
  504. }
  505. return false
  506. }
  507. }
  508. // Not negates a given condition.
  509. func Not(cond Condition) Condition {
  510. return func(ctx context.Context, m ent.Mutation) bool {
  511. return !cond(ctx, m)
  512. }
  513. }
  514. // HasOp is a condition testing mutation operation.
  515. func HasOp(op ent.Op) Condition {
  516. return func(_ context.Context, m ent.Mutation) bool {
  517. return m.Op().Is(op)
  518. }
  519. }
  520. // HasAddedFields is a condition validating `.AddedField` on fields.
  521. func HasAddedFields(field string, fields ...string) Condition {
  522. return func(_ context.Context, m ent.Mutation) bool {
  523. if _, exists := m.AddedField(field); !exists {
  524. return false
  525. }
  526. for _, field := range fields {
  527. if _, exists := m.AddedField(field); !exists {
  528. return false
  529. }
  530. }
  531. return true
  532. }
  533. }
  534. // HasClearedFields is a condition validating `.FieldCleared` on fields.
  535. func HasClearedFields(field string, fields ...string) Condition {
  536. return func(_ context.Context, m ent.Mutation) bool {
  537. if exists := m.FieldCleared(field); !exists {
  538. return false
  539. }
  540. for _, field := range fields {
  541. if exists := m.FieldCleared(field); !exists {
  542. return false
  543. }
  544. }
  545. return true
  546. }
  547. }
  548. // HasFields is a condition validating `.Field` on fields.
  549. func HasFields(field string, fields ...string) Condition {
  550. return func(_ context.Context, m ent.Mutation) bool {
  551. if _, exists := m.Field(field); !exists {
  552. return false
  553. }
  554. for _, field := range fields {
  555. if _, exists := m.Field(field); !exists {
  556. return false
  557. }
  558. }
  559. return true
  560. }
  561. }
  562. // If executes the given hook under condition.
  563. //
  564. // hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
  565. func If(hk ent.Hook, cond Condition) ent.Hook {
  566. return func(next ent.Mutator) ent.Mutator {
  567. return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
  568. if cond(ctx, m) {
  569. return hk(next).Mutate(ctx, m)
  570. }
  571. return next.Mutate(ctx, m)
  572. })
  573. }
  574. }
  575. // On executes the given hook only for the given operation.
  576. //
  577. // hook.On(Log, ent.Delete|ent.Create)
  578. func On(hk ent.Hook, op ent.Op) ent.Hook {
  579. return If(hk, HasOp(op))
  580. }
  581. // Unless skips the given hook only for the given operation.
  582. //
  583. // hook.Unless(Log, ent.Update|ent.UpdateOne)
  584. func Unless(hk ent.Hook, op ent.Op) ent.Hook {
  585. return If(hk, Not(HasOp(op)))
  586. }
  587. // FixedError is a hook returning a fixed error.
  588. func FixedError(err error) ent.Hook {
  589. return func(ent.Mutator) ent.Mutator {
  590. return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
  591. return nil, err
  592. })
  593. }
  594. }
  595. // Reject returns a hook that rejects all operations that match op.
  596. //
  597. // func (T) Hooks() []ent.Hook {
  598. // return []ent.Hook{
  599. // Reject(ent.Delete|ent.Update),
  600. // }
  601. // }
  602. func Reject(op ent.Op) ent.Hook {
  603. hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
  604. return On(hk, op)
  605. }
  606. // Chain acts as a list of hooks and is effectively immutable.
  607. // Once created, it will always hold the same set of hooks in the same order.
  608. type Chain struct {
  609. hooks []ent.Hook
  610. }
  611. // NewChain creates a new chain of hooks.
  612. func NewChain(hooks ...ent.Hook) Chain {
  613. return Chain{append([]ent.Hook(nil), hooks...)}
  614. }
  615. // Hook chains the list of hooks and returns the final hook.
  616. func (c Chain) Hook() ent.Hook {
  617. return func(mutator ent.Mutator) ent.Mutator {
  618. for i := len(c.hooks) - 1; i >= 0; i-- {
  619. mutator = c.hooks[i](mutator)
  620. }
  621. return mutator
  622. }
  623. }
  624. // Append extends a chain, adding the specified hook
  625. // as the last ones in the mutation flow.
  626. func (c Chain) Append(hooks ...ent.Hook) Chain {
  627. newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
  628. newHooks = append(newHooks, c.hooks...)
  629. newHooks = append(newHooks, hooks...)
  630. return Chain{newHooks}
  631. }
  632. // Extend extends a chain, adding the specified chain
  633. // as the last ones in the mutation flow.
  634. func (c Chain) Extend(chain Chain) Chain {
  635. return c.Append(chain.hooks...)
  636. }