|
1
|
|
|
import {AdapterSettingsOptions, ModelStaticInterface} from "../../JeloquentInterfaces"; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
*/ |
|
6
|
|
|
export default class ConnectionSettings { |
|
7
|
|
|
|
|
8
|
|
|
private _baseUrl: string; |
|
9
|
|
|
|
|
10
|
|
|
private cache: string; |
|
11
|
|
|
|
|
12
|
|
|
private contentType: string; |
|
13
|
|
|
|
|
14
|
|
|
private headers: object; |
|
15
|
|
|
|
|
16
|
|
|
private mode: string; |
|
17
|
|
|
|
|
18
|
|
|
private modelPathMappings: Map<string, string>; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
constructor(options: AdapterSettingsOptions) { |
|
24
|
|
|
this.contentType = options?.contentType ?? 'application/json'; |
|
25
|
|
|
this.mode = options?.mode ?? 'cors'; |
|
26
|
|
|
this.cache = options?.cache ?? 'no-cache'; |
|
27
|
|
|
this.headers = options?.headers ?? {}; |
|
28
|
|
|
this._baseUrl = options?.baseUrl ?? 'http://localhost'; |
|
29
|
|
|
this.modelPathMappings = options?.modelPathMappings ?? new Map(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
get baseUrl(): string { |
|
33
|
|
|
return this._baseUrl; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
getSettings(): object { |
|
37
|
|
|
return { |
|
38
|
|
|
"mode": this.mode, // no-cors, *cors, same-origin |
|
39
|
|
|
"cache": this.cache, // *default, no-cache, reload, force-cache, only-if-cached |
|
40
|
|
|
//credentials: 'same-origin', // include, *same-origin, omit |
|
41
|
|
|
"headers": { |
|
42
|
|
|
'Accept': this.contentType, |
|
43
|
|
|
'Content-Type': this.contentType, |
|
44
|
|
|
...this.headers |
|
45
|
|
|
}, |
|
46
|
|
|
"redirect": 'follow', // manual, *follow, error |
|
47
|
|
|
"referrerPolicy": 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url |
|
48
|
|
|
}; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
modelEndPoint(model:ModelStaticInterface): string { |
|
52
|
|
|
return `${this.baseUrl}/${this.modelPathMappings.get(model.className) ?? model.kebabCaseClassName}` |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|