UNPKG

18.6 kBTypeScriptView Raw
1// MOST Web Framework Codename Zero Gravity Copyright (c) 2017-2022, THEMOST LP All rights reserved
2import { ApplicationBase } from './app';
3import { ConfigurationBase } from './config';
4
5export type Types =
6 | 'Float'
7 | 'Boolean'
8 | 'Date'
9 | 'DateTime'
10 | 'Integer'
11 | 'Short'
12 | 'Counter'
13 | 'Duration'
14 | 'Number'
15 | 'Text'
16 | 'Time'
17 | 'URL'
18 | 'Language'
19 | 'Model'
20 | 'Guid'
21 | 'Object'
22 | 'NegativeInteger'
23 | 'NegativeNumber'
24 | 'NonNegativeInteger'
25 | 'NonNegativeNumber'
26 | 'NonPositiveInteger'
27 | 'NonPositiveNumber'
28 | 'PositiveInteger'
29 | 'PositiveNumber'
30 | 'Email'
31 | 'AbsoluteURI'
32 | 'RelativeURI';
33
34export interface DataAssociationMappingBase {
35 associationType?: 'association' | 'junction';
36 associationAdapter?: string;
37 associationObjectField?: string;
38 associationValueField?: string;
39 parentModel?: string;
40 parentField?: string;
41 childModel?: string;
42 childField?: string;
43 cascade?: 'delete' | 'none';
44 options?: {
45 /**
46 * The $orderby system query option specifies the order in which items are returned from the service. e.g. $orderby=dateCreated desc
47 */
48 $orderby?: string;
49 /**
50 * The $select system query option requests that the service return only the properties, dynamic properties requested by the client e.g. $select=id,name,dateCreated
51 */
52 $select?: string;
53 /**
54 * The set of expanded entities can be further refined through the application of expand options, expressed as a semicolon-separated list of system query options.
55 */
56 $expand?: string;
57 /**
58 * The value of the $levels system query option is a positive integer to specify the number of levels to expand e.g. $levels=2
59 */
60 $levels?: string;
61 [k: string]: unknown;
62 };
63 privileges?: {
64 /**
65 * A number which represents permission mask (1=Read, 2=Create, 4=Update, 8=Delete, 16=Execute)
66 */
67 mask: number;
68 /**
69 * A string which represents the permission scope.
70 */
71 type: 'self' | 'global' | 'parent' | 'item';
72 /**
73 * A string which represents the name of the security group where this privilege will be applied e.g. Administrators, Sales etc.
74 */
75 account?: string;
76 /**
77 * A string which represents a filter expression for this privilege. This attribute is used for self privileges which are commonly derived from user's attributes e.g. 'owner eq me()' or 'orderStatus eq 1 and customer eq me()' etc.
78 */
79 filter?: string;
80 [k: string]: unknown;
81 }[];
82 [k: string]: unknown;
83}
84
85export interface DataFieldBase {
86 /**
87 * A string which represents a literal unique identifier for this attribute e.g. https://example.com/models/attributes/name
88 */
89 '@id'?: string;
90 /**
91 * A string which represents a short description of this attribute
92 */
93 description?: string;
94 /**
95 * A string which represents the name of this attribute e.g. title, description, dateCreated etc
96 */
97 name: string;
98 /**
99 * A string which represents a title for this attribute e.g. Date Created etc
100 */
101 title?: string;
102 /**
103 * A string which represents the type of this attribute e.g. Counter, Integer, Number, Text etc
104 */
105 type?: Types | string;
106 /**
107 * A number which represents the maximum size for this attribute e.g. the size of a text field etc
108 */
109 size?: number;
110 /**
111 * A boolean which indicates whether this attribute is nullable or not.
112 */
113 nullable?: boolean;
114 /**
115 * A boolean which indicates whether this attribute is a key column or not.
116 */
117 primary?: boolean;
118 /**
119 * An expression which represents the default value for this attribute.
120 */
121 value?: string;
122 /**
123 * An expression which represents the calculated value for this attribute.
124 */
125 calculation?: string;
126 /**
127 * A boolean which indicates whether this attribute is readonly or not. A readonly value must have a default value or a calculated value.
128 */
129 readonly?: boolean;
130 /**
131 * A boolean which indicates whether this attribute is editable or not.
132 */
133 editable?: boolean;
134 /**
135 * A boolean which indicates whether this attribute is an indexed column or not.
136 */
137 indexed?: boolean;
138 /**
139 * A string which optionally represents the name of this attribute in object mapping. This name may defer from the name of the database field.
140 */
141 property?: string;
142 /**
143 * A boolean value which indicates whether this attribute represents a one-to-many or many-to-many association between two models.
144 */
145 many?: boolean;
146 /**
147 * A boolean value which indicates whether the associated object(s) will be automatically expanded or not.
148 */
149 expandable?: boolean;
150 /**
151 * A boolean which indicates whether this attribute defines an association between two models where child objects are always treated as a part of the parent object.
152 */
153 nested?: boolean;
154 /**
155 * A number which represents the number of digits of a decimal number
156 */
157 scale?: number;
158 /**
159 * A string which defines the multiplicity level of an association between two objects
160 */
161 multiplicity?: 'ZeroOrOne' | 'Many' | 'One' | 'Unknown',
162 mapping?: DataAssociationMappingBase;
163 /**
164 * Defines a data validator for this attribute
165 */
166 validation?: {
167 /**
168 * Sets a value which represents the min value.
169 */
170 minValue?: {
171 [k: string]: unknown;
172 };
173 /**
174 * Sets a value which represents the max value.
175 */
176 maxValue?: {
177 [k: string]: unknown;
178 };
179 /**
180 * Sets a value which represents the min length.
181 */
182 minLength?: number;
183 /**
184 * Sets a value which represents the max allowed length.
185 */
186 maxLength?: number;
187 /**
188 * A string which represents a regular expression that validates values of this attribute.
189 */
190 pattern?: string;
191 /**
192 * A string which represents a message that is going to be used when pattern validation fails.
193 */
194 patternMessage?: string;
195 /**
196 * A string which represents a message that is going to be used when validation fails.
197 */
198 message?: string;
199 /**
200 * Defines a validation against a pre-defined data type e.g. PositiveInteger, URL etc
201 */
202 type?: Types | string;
203 /**
204 * A string which represetns the module path that exports a custom validator e.g. ./validators/custom-validator.js
205 */
206 validator?: string;
207 [k: string]: unknown;
208 };
209 [k: string]: unknown;
210}
211
212export interface DataModelConstraintBase {
213 /**
214 * A string which represents the type of this constraint e.g. unique
215 */
216 type: 'unique';
217 /**
218 * A short description for this constraint e.g. Unique identifier field must be unique across different records.
219 */
220 description?: string;
221 fields?: string[];
222}
223
224export interface DataModelEventListenerBase {
225 /**
226 * A string which the name of this event listener e.g. update person user listener
227 */
228 name?: string;
229 /**
230 * A string which represents the path of the module that exports this listener. This path may be a relative to execution folder path of a module exists in package modules e.g. ./listeners/add-user-listener or my-module/send-mail-listener
231 */
232 type: string;
233}
234
235export interface DataModelPrivilegeBase {
236 /**
237 * A number which represents permission mask (1=Read, 2=Create, 4=Update, 8=Delete, 16=Execute)
238 */
239 mask: number;
240 /**
241 * A string which represents the permission scope.
242 */
243 type: 'self' | 'global' | 'parent' | 'item';
244 /**
245 * A string which represents the name of the security group where this privilege will be applied e.g. Administrators, Sales etc.
246 */
247 account?: string;
248 /**
249 * A string which represents a filter expression for this privilege. This attribute is used for self privileges which are commonly derived from user's attributes e.g. 'owner eq me()' or 'orderStatus eq 1 and customer eq me()' etc.
250 */
251 filter?: string;
252 [k: string]: unknown;
253}
254
255export interface DataModelProperties {
256 /**
257 * A string which represents a literal unique identifier for this model e.g. https://example.com/models/User
258 */
259 '@id'?: string;
260 /**
261 * A string which represents the name of this model e.g. Order, Customer, Person etc
262 */
263 name: string;
264 /**
265 * An optional numeric identifier for this model e.g. 9587891
266 */
267 id?: number;
268 /**
269 * A string which represents the title of this e.g. Supplier Orders, Person Followers etc
270 */
271 title?: string;
272 /**
273 * A string which represents the model which is inherited by this model e.g. User inherits Account, Person inherits Party etc
274 */
275 inherits?: string;
276 /**
277 * A string which represents the model which is implemented by this model e.g. ActionStatusType model implements Enumeration model etc
278 */
279 implements?: string;
280 /**
281 * A boolean which indicates whether this model is being upgraded automatically or not. The default value is false.
282 */
283 sealed?: boolean;
284 /**
285 * A boolean which indicates whether this model is an abstract model or not. The default value is false.
286 */
287 abstract?: boolean;
288 /**
289 * A boolean which indicates whether this model is hidden or not. The default value is false.
290 */
291 hidden?: boolean;
292 /**
293 * A string which represents a module path that exports a class which maps this database model e.g. './models/some-model'
294 */
295 classPath?: string;
296 /**
297 * A string which holds the database object of this model. If this property is missing the database object's name is the concatenation of the model's name and the keyword 'Base' e.g. UserBase, PersonBase etc
298 */
299 source?: string;
300 /**
301 * A string which holds the database object that is going to be used for fetching data. If this property is missing this database object's name is the concatenation of the model's name and the keyword 'Data' e.g. UserData, PersonData etc
302 */
303 view?: string;
304 /**
305 * A string which represents the version of the model's schema. This version is going to be used in model upgrade operations e.g. 1.0, 0.1.2 etc
306 */
307 version: string;
308 /**
309 * A boolean which indicates whether model data will be cached or not. The default value is none -no caching-. A conditional caching allows developers to control caching mechanism while fetching data.
310 */
311 caching?: 'none' | 'always' | 'conditional';
312 fields?: DataFieldBase[];
313 constraints?: DataModelConstraintBase[];
314 eventListeners?: DataModelEventListenerBase[];
315 privileges?: DataModelPrivilegeBase[];
316}
317
318export interface DataModelBase extends DataModelProperties {
319 get context(): DataContextBase;
320 set context(value: DataContextBase);
321 asQueryable(): DataQueryableBase;
322 base(): DataModelBase;
323 clone(): DataModelBase;
324 find(obj: any):DataQueryableBase;
325 getAttribute(name: string): DataFieldBase;
326 getDataObjectType<T>(): new (...args: any) => T;
327 getPrimaryKey(): DataFieldBase;
328 getReferenceMappings(deep?: boolean): DataAssociationMappingBase[];
329 getSubTypes(): string[];
330 getSuperTypes(): string[];
331 inferMapping(attr: any): DataAssociationMappingBase;
332 inferState(obj: any, callback: (err?: Error, res?: any) => void): void;
333 inferStateAsync(obj: any): Promise<any>;
334 insert(obj: any | any[]): Promise<any>;
335 isSilent(): boolean;
336 migrate: ((err?: Error, result?: any) => void);
337 migrateAsync(): Promise<void>;
338 save(obj: any | any[]): Promise<any>;
339 silent(value?: boolean): this;
340 update(obj: any | any[]): Promise<any>;
341 remove(obj: any | any[]): Promise<any>;
342 where(attr: any): DataQueryableBase;
343}
344
345export interface DataAdapterBase {
346 rawConnection?:any;
347 options?:any;
348 open(callback:(err?:Error) => void): void;
349 openAsync(): Promise<void>;
350 close(callback:(err?:Error) => void): void;
351 closeAsync(): Promise<void>;
352 execute(query: any, values: any, callback: (err: Error, result?: any) => void): void;
353 executeAsync(query: any, values: any): Promise<any>;
354 selectIdentity(entity:string, attribute:string , callback?:(err?:Error, result?:any) => void): void;
355 selectIdentityAsync(entity:string, attribute:string): Promise<any>;
356 executeInTransaction(func: () => void, callback:(err?:Error) => void): void;
357 executeInTransactionAsync(func: () => Promise<void>): Promise<void>;
358 migrate(obj: DataAdapterMigration, callback: (err: Error, result?: any) => void): void;
359 migrateAsync(obj: DataAdapterMigration): Promise<any>;
360 createView(name: string, query: any, callback: (err: Error) => void): void;
361}
362
363
364export interface DataContextBase {
365 db?: DataAdapterBase;
366 application?: ApplicationBase;
367
368 model(name:any): DataModelBase;
369 getConfiguration(): ConfigurationBase;
370 finalize(callback?:(err?:Error) => void): void;
371 finalizeAsync(): Promise<void>;
372 executeInTransactionAsync(func: () => Promise<void>): Promise<void>;
373
374}
375
376export interface DataQueryableBase {
377 readonly model: DataModelBase;
378 clone(): DataQueryableBase;
379 where(attr: any): this;
380 search(text: string): this;
381 join(model: any): this;
382 and(attr: any): this;
383 or(attr: any): this;
384 prepare(orElse?: boolean): this;
385 is(value: any): this;
386 equal(value: any): this;
387 notEqual(value: any): this;
388 greaterThan(value: any): this;
389 greaterOEqual(value: any): this;
390 bit(value: any, result?:number): this;
391 lowerThan(value: any): this;
392 lowerOrEqual(value: any): this;
393 startsWith(value: any): this;
394 endsWith(value: any): this;
395 contains(value: any): this;
396 notContains(value: any): this;
397 between(value1: any, value2: any): this;
398 select(...attr: any[]): this;
399 orderBy(attr: any): this;
400 orderByDescending(attr: any): this;
401 thenBy(attr: any): this;
402 thenByDescending(attr: any): this;
403 groupBy(...attr: any[]): this;
404 skip(n:number): this;
405 take(n:number): this;
406 getItem(): Promise<any>;
407 getItems(): Promise<any[]>;
408 getTypedItem<T>(): Promise<T>;
409 getTypedItems<T>(): Promise<T[]>;
410 getList(): Promise<any>;
411 getTypedList(): Promise<any>;
412 getAllItems(): Promise<any[]>;
413 count(): Promise<number>;
414 value(): Promise<any>;
415 min(): Promise<any>;
416 max(): Promise<any>;
417 average(): Promise<any>;
418 silent(value?: boolean): this;
419 cache(value?: boolean): this;
420 expand(...attr: any[]): this;
421 add(x: any): this;
422 subtract(x: any): this;
423 multiply(x: any): this;
424 divide(x: any): this;
425 round(n?:number): this;
426 substr(start: number, length?:number): this;
427 indexOf(s: string): this;
428 concat(s: string): this;
429 trim(): this;
430 length(): this;
431 getDate(): this;
432 getYear(): this;
433 getMonth(): this;
434 getDay(): this;
435 getFullYear(): this;
436 getMinutes(): this;
437 getSeconds(): this;
438 getHours(): this;
439 floor(): this;
440 ceil(): this;
441 toLowerCase(): this;
442 toLocaleLowerCase(): this;
443 toUpperCase(): this;
444 toLocaleUpperCase(): this;
445 levels(n:number): this;
446}
447
448export interface DataObjectBase {
449
450 context?: DataContextBase;
451 getType(): any;
452 getId():any;
453 save(context?: DataContextBase): Promise<void>;
454 remove(context?: DataContextBase): Promise<void>;
455 getModel(): DataModelBase;
456 getAdditionalModel():Promise<DataModelBase>;
457 getAdditionalObject():Promise<DataContextBase|any>;
458 query(attr:string):DataQueryableBase;
459
460}
461
462export declare interface DataAdapterTable {
463 create(fields: Array<any>, callback: (err: Error) => void): void;
464 createAsync(fields: Array<any>): Promise<void>;
465 add(fields: Array<any>, callback: (err: Error) => void): void;
466 addAsync(fields: Array<any>): Promise<void>;
467 change(fields: Array<any>, callback: (err: Error) => void): void;
468 changeAsync(fields: Array<any>): Promise<void>;
469 exists(callback: (err: Error, result: boolean) => void): void;
470 existsAsync(): Promise<boolean>;
471 version(callback: (err: Error, result: string) => void): void;
472 versionAsync(): Promise<string>;
473 columns(callback: (err: Error, result: Array<any>) => void): void;
474 columnsAsync(): Promise<Array<any>>;
475}
476
477export declare interface DataAdapterIndex {
478 name: string;
479 columns: Array<string>;
480}
481
482export declare interface DataAdapterIndexes {
483 create(name: string, columns: Array<string>, callback: (err: Error, res?: number) => void): void;
484 createAsync(name: string, columns: Array<string>): Promise<number>;
485 drop(name: string, callback: (err: Error, res?: number) => void): void;
486 dropAsync(name: string): Promise<number>;
487 list(callback: (err: Error, res: Array<DataAdapterIndex>) => void): void;
488 listAsync(): Promise<Array<DataAdapterIndex>>;
489}
490
491export declare interface DataAdapterView {
492 create(query: any, callback: (err: Error) => void): void;
493 createAsync(query: any): Promise<void>;
494 exists(callback: (err: Error, result: boolean) => void): void;
495 existsAsync(): Promise<boolean>;
496 drop(callback: (err: Error) => void): void;
497 dropAsync(): Promise<void>;
498}
499
500export declare interface DataAdapterDatabase {
501 exists(callback: (err: Error, result: boolean) => void): void;
502 existsAsync(): Promise<boolean>;
503 create(callback: (err: Error) => void): void;
504 createAsync(): Promise<void>;
505}
506
507export declare interface DataAdapterMigration {
508 add: Array<any>;
509 change?: Array<any>;
510 appliesTo: string;
511 version: string;
512 indexes?: Array<{name: string, columns: Array<string>}>;
513 updated: boolean;
514}
515
516export declare interface DataAdapterBaseHelper {
517 table(name: string): DataAdapterTable;
518 view(name: string): DataAdapterView;
519 indexes(name: string): DataAdapterIndexes;
520 database(name: string): DataAdapterDatabase;
521}
\No newline at end of file