UNPKG

19.3 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
351 close(callback:(err?:Error) => void): void;
352 closeAsync(): Promise<void>;
353
354 execute(query:any, values:any[], callback:(err?:Error, result?:any) => void): void;
355 executeAsync(query:any, values:any[]): Promise<void>;
356
357 selectIdentity(entity:string, attribute:string , callback?:(err?:Error, result?:any) => void): void;
358 selectIdentityAsync(entity:string, attribute:string): Promise<void>;
359
360 executeInTransaction(func: () => void, callback:(err?:Error) => void): void;
361 executeInTransactionAsync(func: () => Promise<void>): Promise<void>;
362}
363
364
365export interface DataContextBase {
366 db?: DataAdapterBase;
367 application?: ApplicationBase;
368
369 model(name:any): DataModelBase;
370 getConfiguration(): ConfigurationBase;
371 finalize(callback?:(err?:Error) => void): void;
372 finalizeAsync(): Promise<void>;
373 executeInTransactionAsync(func: () => Promise<void>): Promise<void>;
374
375}
376
377export interface DataQueryableBase {
378 readonly model: DataModelBase;
379 clone(): DataQueryableBase;
380 where(attr: any): this;
381 search(text: string): this;
382 join(model: any): this;
383 and(attr: any): this;
384 or(attr: any): this;
385 prepare(orElse?: boolean): this;
386 is(value: any): this;
387 equal(value: any): this;
388 notEqual(value: any): this;
389 greaterThan(value: any): this;
390 greaterOEqual(value: any): this;
391 bit(value: any, result?:number): this;
392 lowerThan(value: any): this;
393 lowerOrEqual(value: any): this;
394 startsWith(value: any): this;
395 endsWith(value: any): this;
396 contains(value: any): this;
397 notContains(value: any): this;
398 between(value1: any, value2: any): this;
399 select(...attr: any[]): this;
400 orderBy(attr: any): this;
401 orderByDescending(attr: any): this;
402 thenBy(attr: any): this;
403 thenByDescending(attr: any): this;
404 groupBy(...attr: any[]): this;
405 skip(n:number): this;
406 take(n:number): this;
407 getItem(): Promise<any>;
408 getItems(): Promise<any[]>;
409 getTypedItem<T>(): Promise<T>;
410 getTypedItems<T>(): Promise<T[]>;
411 getList(): Promise<any>;
412 getTypedList(): Promise<any>;
413 getAllItems(): Promise<any[]>;
414 count(): Promise<number>;
415 value(): Promise<any>;
416 min(): Promise<any>;
417 max(): Promise<any>;
418 average(): Promise<any>;
419 silent(value?: boolean): this;
420 cache(value?: boolean): this;
421 expand(...attr: any[]): this;
422 add(x: any): this;
423 subtract(x: any): this;
424 multiply(x: any): this;
425 divide(x: any): this;
426 round(n?:number): this;
427 substr(start: number, length?:number): this;
428 indexOf(s: string): this;
429 concat(s: string): this;
430 trim(): this;
431 length(): this;
432 getDate(): this;
433 getYear(): this;
434 getMonth(): this;
435 getDay(): this;
436 getFullYear(): this;
437 getMinutes(): this;
438 getSeconds(): this;
439 getHours(): this;
440 floor(): this;
441 ceil(): this;
442 toLowerCase(): this;
443 toLocaleLowerCase(): this;
444 toUpperCase(): this;
445 toLocaleUpperCase(): this;
446 levels(n:number): this;
447}
448
449export interface DataObjectBase {
450
451 context?: DataContextBase;
452 getType(): any;
453 getId():any;
454 save(context?: DataContextBase): Promise<void>;
455 remove(context?: DataContextBase): Promise<void>;
456 getModel(): DataModelBase;
457 getAdditionalModel():Promise<DataModelBase>;
458 getAdditionalObject():Promise<DataContextBase|any>;
459 query(attr:string):DataQueryableBase;
460
461}
462
463export declare interface DataAdapterTable {
464 create(fields: Array<any>, callback: (err: Error) => void): void;
465 createAsync(fields: Array<any>): Promise<void>;
466 add(fields: Array<any>, callback: (err: Error) => void): void;
467 addAsync(fields: Array<any>): Promise<void>;
468 change(fields: Array<any>, callback: (err: Error) => void): void;
469 changeAsync(fields: Array<any>): Promise<void>;
470 exists(callback: (err: Error, result: boolean) => void): void;
471 existsAsync(): Promise<boolean>;
472 version(callback: (err: Error, result: string) => void): void;
473 versionAsync(): Promise<string>;
474 columns(callback: (err: Error, result: Array<any>) => void): void;
475 columnsAsync(): Promise<Array<any>>;
476}
477
478export declare interface DataAdapterIndex {
479 name: string;
480 columns: Array<string>;
481}
482
483export declare interface DataAdapterIndexes {
484 create(name: string, columns: Array<string>, callback: (err: Error, res?: number) => void): void;
485 createAsync(name: string, columns: Array<string>): Promise<number>;
486 drop(name: string, callback: (err: Error, res?: number) => void): void;
487 dropAsync(name: string): Promise<number>;
488 list(callback: (err: Error, res: Array<DataAdapterIndex>) => void): void;
489 listAsync(): Promise<Array<DataAdapterIndex>>;
490}
491
492export declare interface DataAdapterView {
493 create(query: any, callback: (err: Error) => void): void;
494 createAsync(query: any): Promise<void>;
495 exists(callback: (err: Error, result: boolean) => void): void;
496 existsAsync(): Promise<boolean>;
497 drop(callback: (err: Error) => void): void;
498 dropAsync(): Promise<void>;
499}
500
501export declare interface DataAdapterDatabase {
502 exists(callback: (err: Error, result: boolean) => void): void;
503 existsAsync(): Promise<boolean>;
504 create(callback: (err: Error) => void): void;
505 createAsync(): Promise<void>;
506}
507
508export declare interface DataAdapterMigration {
509 add: Array<any>;
510 change?: Array<any>;
511 appliesTo: string;
512 version: string;
513 indexes?: Array<{name: string, columns: Array<string>}>;
514 updated: boolean;
515}
516
517export declare interface DataAdapterBase {
518 constructor(options?: any);
519 formatType(field: any): string;
520 open(callback: (err: Error) => void): void;
521 close(callback: (err: Error) => void): void;
522 openAsync(): Promise<void>;
523 closeAsync(): Promise<void>;
524 prepare(query: any, values?: Array<any>): any;
525 createView(name: string, query: any, callback: (err: Error) => void): void;
526 executeInTransaction(func: any, callback: (err: Error) => void): void;
527 executeInTransactionAsync(func: Promise<any>): Promise<any>;
528 migrate(obj: DataAdapterMigration, callback: (err: Error, result?: any) => void): void;
529 migrateAsync(obj: DataAdapterMigration): Promise<any>;
530 selectIdentity(entity: string, attribute: string, callback: (err: Error, value: any) => void): void;
531 execute(query: any, values: any, callback: (err: Error, value: any) => void): void;
532 executeAsync(query: any, values: any): Promise<any>;
533 executeAsync<T>(query: any, values: any): Promise<Array<T>>;
534 table(name: string): DataAdapterTable;
535 view(name: string): DataAdapterView;
536 indexes(name: string): DataAdapterIndexes;
537 database(name: string): DataAdapterDatabase;
538}
\No newline at end of file