-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdecorator.ts
157 lines (144 loc) · 4.43 KB
/
decorator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
declare module '@ioc:Adonis/Addons/AdminJS' {
import { PropertyType } from 'adminjs'
import {
LucidModel,
LucidRow,
ModelQueryBuilderContract,
} from '@ioc:Adonis/Lucid/Orm'
export type AdminColumnOptions = {
/**
* Name of field.
*/
name: string
/**
* Position of display in the form.
* Defaults to 1
*/
position: number
/**
* Type of field.
*/
type?: PropertyType | 'file'
/**
* Whether field is visible or not. Defaults to true
*/
visible: boolean
/**
* Whether field is editable or not. Defaults to false for primary key & true for all others
*/
editable: boolean
/**
* Whether field is unique or not. Defaults to true for primary key & false for all others
*/
unique: boolean
/**
* Available enum options for this field.
*/
enum?: Record<string, any>
/**
* Whether field is sortable or not. Defaults to true
*/
sortable: boolean
/**
* Whether field is optional or not. Defaults to false
*/
optional: boolean
/**
* Function to convert attribute to displayable value
*/
serialize?: (
value: any,
attribute: string,
instance: LucidRow
) => any | Promise<any>
}
export function adminColumn(
options: Partial<AdminColumnOptions>
): (target: LucidRow, property: string) => void
/**
* Type for decorators providing hook functionalities
*/
export type HookDecorator<ArgType> = () => <
Property extends string,
T extends LucidModel &
Record<Property, (arg: ArgType) => Promise<void> | void>
>(
target: T,
property: Property
) => void
/**
* Before create hook.
* Executed after all parameters have been validated but before save is called.
*
* Runs before the original 'beforeCreate' hook of AdonisJS
*/
export const beforeCreate: HookDecorator<LucidRow>
/**
* Before update hook.
* Executed after all parameters have been validated but before save is called.
*
* Runs before the original 'beforeUpdate' hook of AdonisJS
*/
export const beforeUpdate: HookDecorator<LucidRow>
/**
* Before delete hook.
*
* Runs before the original 'beforeDelete' hook of AdonisJS
*/
export const beforeDelete: HookDecorator<LucidRow>
/**
* Before find hook.
* Executed when a single object is fetched i.e on show & edit pages.
*
* Runs before the original 'beforeFind' hook of AdonisJS
*/
export const beforeFind: HookDecorator<
ModelQueryBuilderContract<LucidModel>
>
/**
* Before fetch hook.
* Executed when multiple objects are fetched i.e on list & filter pages
* or when the list of objects is displayed in select box of related fields.
*
* Runs before the original 'beforeCreate' hook of AdonisJS
*/
export const beforeFetch: HookDecorator<
ModelQueryBuilderContract<LucidModel>
>
/**
* After create hook.
* Only called if create operation is completed successfully.
*
* Runs after the original 'afterCreate' hook of AdonisJS
*/
export const afterCreate: HookDecorator<LucidRow>
/**
* After update hook.
* Only called if update operation is completed successfully.
*
* Runs after the original 'afterUpdate' hook of AdonisJS
*/
export const afterUpdate: HookDecorator<LucidRow>
/**
* After delete hook.
* Only called if delete operation is completed successfully.
*
* Runs after the original 'afterDelete' hook of AdonisJS
*/
export const afterDelete: HookDecorator<LucidRow>
/**
* After find hook.
* Executed when a single object is fetched i.e on show & edit pages.
*
* Runs after the original 'afterFind' hook of AdonisJS
*/
export const afterFind: HookDecorator<LucidRow>
/**
* After fetch hook.
* Executed when multiple objects are fetched i.e on list & filter pages
* or when the list of objects is displayed in select box of related fields.
*
* Runs after the original 'beforeCreate' hook of AdonisJS
*/
export const afterFetch: HookDecorator<LucidRow[]>
}