MCPcopy Create free account
hub / github.com/axe-api/axe-api / ModelService

Class ModelService

packages/axe-api/src/Services/ModelService.ts:12–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import { ModelHooks, PhaseFunction, SerializationFunction } from "../Types";
11
12class ModelService implements IModelService {
13 name: string;
14 instance: Model;
15 relations: IRelation[];
16 columns: IColumn[];
17 columnNames: string[];
18 hooks: ModelHooks = {} as ModelHooks;
19 events: ModelHooks = {} as ModelHooks;
20 children: IModelService[];
21 isRecursive: boolean;
22 queryLimits: IQueryLimitConfig[];
23 serialize: SerializationFunction | null;
24 cacheConfiguration: Record<string, ICacheConfiguration>;
25
26 constructor(name: string, instance: Model) {
27 this.name = name;
28 this.instance = instance;
29 this.relations = [];
30 this.columns = [];
31 this.columnNames = [];
32 this.children = [];
33 this.isRecursive = false;
34 this.queryLimits = [];
35 this.serialize = null;
36 this.cacheConfiguration = {};
37 }
38
39 setColumns(columns: IColumn[]) {
40 this.columns = columns;
41 this.columnNames = this.columns.map((i) => i.name);
42 }
43
44 setCacheConfiguration(handler: string, cache: ICacheConfiguration) {
45 this.cacheConfiguration[handler] = cache;
46 }
47
48 getCacheConfiguration(handler: HandlerTypes) {
49 return this.cacheConfiguration[handler];
50 }
51
52 setExtensions(
53 type: Extensions,
54 hookFunctionType: HookFunctionTypes,
55 data: PhaseFunction,
56 ) {
57 if (type == Extensions.Hooks) {
58 this.setHooks(hookFunctionType, data);
59 } else if (type == Extensions.Events) {
60 this.setEvents(hookFunctionType, data);
61 } else {
62 throw new Error("Undefined hook type.");
63 }
64 }
65
66 setQueryLimits(limits: IQueryLimitConfig[]) {
67 this.queryLimits = limits;
68 }
69

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected