1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | declare namespace FxOrmModel {
|
12 | type ModelInstanceConstructorOptions = (string | number | FxOrmInstance.InstanceDataPayload)[]
|
13 |
|
14 | interface ModelInstanceConstructor {
|
15 | (): FxOrmInstance.Instance;
|
16 | new(): FxOrmInstance.Instance;
|
17 | (...data: ModelInstanceConstructorOptions): FxOrmInstance.Instance;
|
18 | new(...data: ModelInstanceConstructorOptions): FxOrmInstance.Instance;
|
19 | }
|
20 |
|
21 | type OrderListOrLimitOffer = number | string | string[]
|
22 | interface Model extends ModelInstanceConstructor, ModelHooks, FxOrmSynchronous.SynchronizedModel {
|
23 | name: string;
|
24 | properties: FxOrmProperty.NormalizedPropertyHash;
|
25 | settings: FxOrmSettings.SettingInstance;
|
26 |
|
27 | table: string;
|
28 | id: string[];
|
29 |
|
30 | uid: string;
|
31 |
|
32 | caches: Class_LruCache;
|
33 |
|
34 | keys: string[];
|
35 |
|
36 | allProperties: FxOrmProperty.NormalizedPropertyHash
|
37 |
|
38 |
|
39 | addProperty: {
|
40 | (
|
41 | propIn: FxOrmProperty.NormalizedProperty,
|
42 | options?: {
|
43 | name?: string
|
44 | klass?: FxOrmProperty.KlassType
|
45 | } | false
|
46 | ): FxOrmProperty.NormalizedProperty
|
47 | }
|
48 |
|
49 |
|
50 | sync(callback?: FxOrmNS.GenericCallback<FxOrmSqlDDLSync.SyncResult>): Model;
|
51 | drop(callback?: FxOrmNS.VoidCallback): Model;
|
52 |
|
53 | |
54 |
|
55 |
|
56 |
|
57 | hasOne: {
|
58 | (assoc_name: string, ext_model?: Model, assoc_options?: FxOrmAssociation.AssociationDefinitionOptions_HasOne): FxOrmModel.Model
|
59 | }
|
60 | hasMany: {
|
61 | (assoc_name: string, ext_model: Model, assoc_options?: FxOrmAssociation.AssociationDefinitionOptions_HasMany): FxOrmModel.Model
|
62 | (assoc_name: string, ext_model: Model, assoc_props: ModelPropertyDefinitionHash, assoc_options?: FxOrmAssociation.AssociationDefinitionOptions_HasMany): FxOrmModel.Model
|
63 | }
|
64 | extendsTo: {
|
65 | (name: string, properties: ModelPropertyDefinitionHash, assoc_options?: FxOrmAssociation.AssociationDefinitionOptions_ExtendsTo): Model
|
66 | };
|
67 |
|
68 | associations: {
|
69 | [k: string]: {
|
70 | type: 'hasOne'
|
71 | association: FxOrmAssociation.InstanceAssociationItem_HasOne
|
72 | } | {
|
73 | type: 'hasMany'
|
74 | association: FxOrmAssociation.InstanceAssociationItem_HasMany
|
75 | } | {
|
76 | type: 'extendsTo'
|
77 | association: FxOrmAssociation.InstanceAssociationItem_ExtendTos
|
78 | }
|
79 | }
|
80 | findBy: {
|
81 | <T = any>(
|
82 | association_name: ModelFindByDescriptorItem['association_name'],
|
83 | conditions?: ModelFindByDescriptorItem['conditions'],
|
84 | options?: ModelFindByDescriptorItem['options'],
|
85 | cb?: FxOrmNS.ExecutionCallback<T>
|
86 | ): FxOrmQuery.IChainFind
|
87 | <T = any>(
|
88 | list: ModelFindByDescriptorItem[],
|
89 | self_conditions: FxOrmModel.ModelQueryConditions__Find,
|
90 | cb?: FxOrmNS.ExecutionCallback<T>
|
91 | ): FxOrmQuery.IChainFind
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 | create: {
|
97 | (data: FxOrmInstance.InstanceDataPayload, callback?: ModelMethodCallback__CreateItem): Model;
|
98 | (data: FxOrmInstance.InstanceDataPayload, options?: ModelOptions__Create, callback?: ModelMethodCallback__CreateItem): Model;
|
99 | }
|
100 | clear: {
|
101 | (...args: any[]): Model;
|
102 | }
|
103 | get: {
|
104 | (...ids: any[]): Model;
|
105 | }
|
106 |
|
107 | chain: {
|
108 | (conditions?: FxOrmModel.ModelQueryConditions__Find, ...args: (FxOrmModel.ModelOptions__Find | OrderListOrLimitOffer)[]): FxOrmQuery.IChainFind;
|
109 | }
|
110 |
|
111 | find: {
|
112 | (conditions?: ModelQueryConditions__Find): FxOrmQuery.IChainFind
|
113 | (callback: ModelMethodCallback__Find): Model
|
114 | (conditions: ModelQueryConditions__Find, callback: ModelMethodCallback__Find): Model
|
115 |
|
116 | (conditions: ModelQueryConditions__Find, options: ModelOptions__Find): FxOrmQuery.IChainFind
|
117 | (conditions: ModelQueryConditions__Find, options: ModelOptions__Find, callback: ModelMethodCallback__Find): Model
|
118 |
|
119 | (conditions: ModelQueryConditions__Find, limit_order?: OrderListOrLimitOffer, limit_order2?: OrderListOrLimitOffer): FxOrmQuery.IChainFind
|
120 |
|
121 | (conditions: ModelQueryConditions__Find, limit_order: OrderListOrLimitOffer, callback: ModelMethodCallback__Find): Model
|
122 | (conditions: ModelQueryConditions__Find, limit_order: OrderListOrLimitOffer, limit_order2: OrderListOrLimitOffer, callback: ModelMethodCallback__Find): Model
|
123 | }
|
124 |
|
125 | all: Model['find']
|
126 | where: Model['find']
|
127 |
|
128 | |
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 | one: {
|
137 | (callback: ModelMethodCallback__Get): Model;
|
138 | (conditions: ModelQueryConditions__Find, callback: ModelMethodCallback__Get): Model;
|
139 | (conditions: ModelQueryConditions__Find, options: ModelOptions__Find, callback: ModelMethodCallback__Get): Model;
|
140 | (conditions: ModelQueryConditions__Find, order: string[], callback: ModelMethodCallback__Get): Model;
|
141 | (conditions: ModelQueryConditions__Find, limit: number, callback: ModelMethodCallback__Get): Model;
|
142 | }
|
143 |
|
144 | count: {
|
145 | (callback: ModelMethodCallback__Count): Model;
|
146 | (conditions: ModelQueryConditions__Find, callback: ModelMethodCallback__Count): Model;
|
147 | }
|
148 |
|
149 | exists: {
|
150 | (...conditions: (FibOrmNS.IdType | FxSqlQuerySubQuery.SubQueryConditions | FxOrmNS.ExecutionCallback<boolean>)[]): FxOrmQuery.IChainFind
|
151 | }
|
152 |
|
153 | aggregate: {
|
154 | (conditions: ModelQueryConditions__Find): FxOrmQuery.IAggregated;
|
155 | (properties: string[]): FxOrmQuery.IAggregated;
|
156 | (conditions: ModelQueryConditions__Find, properties: string[]): FxOrmQuery.IAggregated;
|
157 | }
|
158 |
|
159 |
|
160 | prependValidation: {
|
161 | (key: string, validation: FibjsEnforce.IValidator): void
|
162 | }
|
163 |
|
164 | [property: string]: any;
|
165 | }
|
166 |
|
167 | type FindByListStyleFunctionArgs<T = any> = [
|
168 | FxOrmModel.ModelFindByDescriptorItem[],
|
169 | FxOrmModel.ModelQueryConditions__Find,
|
170 | FxOrmModel.ModelOptions__Find,
|
171 | FxOrmNS.ExecutionCallback<T>
|
172 | ]
|
173 |
|
174 | type FindByItemStyleFunctionArgs<T = any> = [
|
175 | FxOrmModel.ModelFindByDescriptorItem['association_name'],
|
176 | FxOrmModel.ModelFindByDescriptorItem['conditions'],
|
177 | FxOrmModel.ModelFindByDescriptorItem['options'],
|
178 | FxOrmNS.ExecutionCallback<T>
|
179 | ]
|
180 |
|
181 | type ModelConstructor = new (opts: ModelConstructorOptions) => Model
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | interface ModelFindByDescriptorItem {
|
188 |
|
189 | association_name: string,
|
190 |
|
191 | conditions?: ModelQueryConditions__Find,
|
192 |
|
193 | options?: FxOrmAssociation.ModelAssociationMethod__FindByOptions,
|
194 |
|
195 |
|
196 | join_where?: FxOrmModel.ModelQueryConditions__Find
|
197 |
|
198 | extra_select?: string[]
|
199 | }
|
200 |
|
201 | interface ModelConstructorOptions {
|
202 | name: string
|
203 | db: FxOrmNS.ORM
|
204 | settings: FxOrmSettings.SettingInstance
|
205 | driver_name: string
|
206 | driver: FxOrmDMLDriver.DMLDriver
|
207 | table: string
|
208 | properties: FxOrmProperty.NormalizedPropertyHash
|
209 | __for_extension: boolean
|
210 | indexes: string[]
|
211 |
|
212 | identityCache: boolean
|
213 | instanceCacheSize: number
|
214 |
|
215 | keys: string[]
|
216 | autoSave: boolean
|
217 | autoFetch: boolean
|
218 | autoFetchLimit: number
|
219 | cascadeRemove: boolean
|
220 | hooks: Hooks
|
221 | methods: {[method_name: string]: Function}
|
222 | validations: FxOrmValidators.IValidatorHash
|
223 | ievents: FxOrmInstance.InstanceConstructorOptions['events']
|
224 | }
|
225 |
|
226 | interface ModelDefineOptions {
|
227 | |
228 |
|
229 |
|
230 | table?: ModelConstructorOptions['table']
|
231 | collection?: ModelConstructorOptions['table']
|
232 |
|
233 | |
234 |
|
235 |
|
236 | __for_extension?: ModelConstructorOptions['__for_extension']
|
237 | indexes?: ModelConstructorOptions['indexes']
|
238 |
|
239 | id?: ModelConstructorOptions['keys']
|
240 | autoSave?: ModelConstructorOptions['autoSave']
|
241 | autoFetch?: ModelConstructorOptions['autoFetch']
|
242 | autoFetchLimit?: ModelConstructorOptions['autoFetchLimit']
|
243 | hooks?: ModelConstructorOptions['hooks']
|
244 | validations?: ModelConstructorOptions['validations']
|
245 | methods?: { [name: string]: Function };
|
246 | identityCache?: ModelConstructorOptions['identityCache']
|
247 | cascadeRemove?: ModelConstructorOptions['cascadeRemove']
|
248 | ievents?: ModelConstructorOptions['ievents']
|
249 | useSelfSettings?: boolean
|
250 |
|
251 | [extensibleProperty: string]: any;
|
252 | }
|
253 | type ModelOptions = ModelDefineOptions
|
254 |
|
255 | interface Hooks {
|
256 | beforeValidation?: FxOrmNS.Arraible<FxOrmHook.HookActionCallback>;
|
257 | beforeCreate?: FxOrmNS.Arraible<FxOrmHook.HookActionCallback>;
|
258 | afterCreate?: FxOrmNS.Arraible<FxOrmHook.HookResultCallback>;
|
259 | beforeSave?: FxOrmNS.Arraible<FxOrmHook.HookActionCallback>;
|
260 | afterSave?: FxOrmNS.Arraible<FxOrmHook.HookResultCallback>;
|
261 | afterLoad?: FxOrmNS.Arraible<FxOrmHook.HookActionCallback>;
|
262 | afterAutoFetch?: FxOrmNS.Arraible<FxOrmHook.HookActionCallback>;
|
263 | beforeRemove?: FxOrmNS.Arraible<FxOrmHook.HookActionCallback>;
|
264 | afterRemove?: FxOrmNS.Arraible<FxOrmHook.HookResultCallback>;
|
265 | }
|
266 | type keyofHooks = keyof Hooks
|
267 |
|
268 | interface ModelHookPatchOptions extends FxOrmHook.HookPatchOptions {
|
269 | }
|
270 |
|
271 | interface ModelHooks {
|
272 | beforeValidation?: {
|
273 | (func: FxOrmHook.HookActionCallback, opts?: ModelHookPatchOptions): any
|
274 | };
|
275 | beforeCreate?: {
|
276 | (func: FxOrmHook.HookActionCallback, opts?: ModelHookPatchOptions): any
|
277 | };
|
278 | afterCreate?: {
|
279 | (func: FxOrmHook.HookActionCallback, opts?: ModelHookPatchOptions): any
|
280 | };
|
281 | beforeSave?: {
|
282 | (func: FxOrmHook.HookActionCallback, opts?: ModelHookPatchOptions): any
|
283 | };
|
284 | afterSave?: {
|
285 | (func: FxOrmHook.HookResultCallback, opts?: ModelHookPatchOptions): any
|
286 | };
|
287 | afterLoad?: {
|
288 | (func: FxOrmHook.HookResultCallback, opts?: ModelHookPatchOptions): any
|
289 | };
|
290 | afterAutoFetch?: {
|
291 | (func: FxOrmHook.HookActionCallback, opts?: ModelHookPatchOptions): any
|
292 | };
|
293 | beforeRemove?: {
|
294 | (func: FxOrmHook.HookActionCallback, opts?: ModelHookPatchOptions): any
|
295 | };
|
296 | afterRemove?: {
|
297 | (func: FxOrmHook.HookResultCallback, opts?: ModelHookPatchOptions): any
|
298 | };
|
299 | }
|
300 |
|
301 | interface ModelPropertyDefinition extends FxOrmSqlDDLSync__Column.Property {
|
302 | key?: boolean
|
303 | klass?: FxOrmProperty.KlassType
|
304 | alwaysValidate?: boolean
|
305 | enumerable?: boolean
|
306 |
|
307 | lazyload?: boolean
|
308 | }
|
309 |
|
310 |
|
311 | type OrigDetailedModelProperty = FxOrmProperty.NormalizedProperty
|
312 | type OrigDetailedModelPropertyHash = FxOrmProperty.NormalizedPropertyHash
|
313 |
|
314 | type PrimitiveConstructor = String | Boolean | Number | Date | Object | Class_Buffer
|
315 | type EnumTypeValues = any[]
|
316 | type PropTypeStrPropertyDefinition = string
|
317 |
|
318 | type ComplexModelPropertyDefinition =
|
319 | ModelPropertyDefinition
|
320 | | (PrimitiveConstructor & {
|
321 | name: string
|
322 | })
|
323 | | EnumTypeValues
|
324 | | PropTypeStrPropertyDefinition
|
325 |
|
326 | type ModelPropertyDefinitionHash = {
|
327 | [key: string]: ComplexModelPropertyDefinition
|
328 | }
|
329 |
|
330 | interface DetailedPropertyDefinitionHash {
|
331 | [key: string]: ModelPropertyDefinition
|
332 | }
|
333 |
|
334 | interface ModelOptions__Find {
|
335 | chainfind_linktable?: string;
|
336 |
|
337 | only?: string[];
|
338 | limit?: number;
|
339 | order?: FxOrmQuery.OrderRawInput | FxOrmQuery.ChainFindOptions['order']
|
340 |
|
341 | offset?: number;
|
342 | identityCache?: boolean
|
343 |
|
344 | autoFetch?: boolean
|
345 | cascadeRemove?: boolean
|
346 | autoSave?: boolean
|
347 | autoFetchLimit?: number
|
348 | __merge?: FxOrmQuery.ChainFindOptions['merge']
|
349 | exists?: FxOrmQuery.ChainWhereExistsInfo[]
|
350 |
|
351 |
|
352 | extra?: FxOrmAssociation.InstanceAssociationItem_HasMany['props']
|
353 |
|
354 |
|
355 | [k: string]: any
|
356 | }
|
357 |
|
358 | interface ModelOptions__Findby extends ModelOptions__Find {
|
359 |
|
360 | }
|
361 |
|
362 | interface ModelOptions__Get extends ModelOptions__Find {}
|
363 |
|
364 | interface ModelQueryConditions__Find extends FxSqlQuerySubQuery.SubQueryConditions {
|
365 | [property: string]: any
|
366 | }
|
367 |
|
368 | type ModelQueryConditionsItem = FxSqlQuerySql.SqlFragmentStr | ModelQueryConditions__Find
|
369 |
|
370 | type ModelMethodOptions_Find = FxOrmNS.IdType | ModelQueryConditions__Find
|
371 |
|
372 | type ModelMethodCallback__Boolean = FxOrmNS.GenericCallback<Boolean>
|
373 | type ModelMethodCallback__Find = FxOrmNS.GenericCallback<FxOrmInstance.Instance[]>
|
374 | type ModelMethodCallback__Get = FxOrmNS.GenericCallback<FxOrmInstance.Instance>
|
375 | type ModelMethodCallback__CreateItem = FxOrmNS.GenericCallback<FxOrmInstance.Instance>
|
376 | type ModelMethodCallback__UpdateItem = FxOrmNS.GenericCallback<FxOrmInstance.Instance>
|
377 | type ModelMethodCallback__BatchCreate = FxOrmNS.GenericCallback<FxOrmInstance.Instance[]>
|
378 | type ModelMethodCallback__BatchUpdate = FxOrmNS.GenericCallback<FxOrmInstance.Instance[]>
|
379 |
|
380 | type ModelMethodCallback__Count = FxOrmNS.GenericCallback<number>
|
381 |
|
382 | interface ModelOptions__Create {
|
383 | parallel?: boolean
|
384 | }
|
385 | }
|