-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathknowledge.js
194 lines (165 loc) · 5.76 KB
/
knowledge.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { stringify } from 'qs';
import { KNOWLEDGE_API_BASE } from '../api-version';
const URL_PATH_INSTANCE = 'instance';
const URL_PATH_DEPLOYED = 'deployed';
const URL_PATH_DEPLOY = 'deploy';
const URL_PATH_POOLS = 'pools';
const URL_PATH_KIS = 'kis';
const URL_PATH_POOL = 'pool';
const URL_PATH_KI = 'ki';
const URL_PATH_HISTORY = 'history';
const toPath = (...paths) => `${KNOWLEDGE_API_BASE}/${paths.join('/')}`;
export default function knowledgeServletFactory(fetch, options) {
return {
// All Visible Pools (perspective of Engine)
pools: (scopeId) =>
fetch(toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_POOLS), options),
// All Visible Kis (perspective of Engine)
kis: (scopeId) =>
fetch(toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_KIS), options),
// Search All Visible Kis (perspective of Engine)
search: (scopeId, searchTerms) =>
fetch(
toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_KIS) +
`?${stringify({ search: [...searchTerms] })}`,
options,
),
// All Deployed Pools to Instance / Engine
poolsDeployed: (scopeId) =>
fetch(
toPath(
URL_PATH_INSTANCE,
scopeId,
URL_PATH_DEPLOYED,
URL_PATH_POOLS,
),
options,
),
// All Deployed Kis to Instance / Engine (via Pool)
kisDeployed: (scopeId) =>
fetch(
toPath(
URL_PATH_INSTANCE,
scopeId,
URL_PATH_DEPLOYED,
URL_PATH_KIS,
),
options,
),
// Check if Pool is Deployed to Instance / Engine
poolDeployed: (scopeId, poolId) =>
fetch(
toPath(
URL_PATH_INSTANCE,
scopeId,
URL_PATH_DEPLOYED,
URL_PATH_POOL,
poolId,
),
options,
),
// Check if Ki is Deployed to Instance / Engine
kiDeployed: (scopeId, kiId) =>
fetch(
toPath(
URL_PATH_INSTANCE,
scopeId,
URL_PATH_DEPLOYED,
URL_PATH_KI,
kiId,
),
options,
),
kiDeployedStatuses: (scopeId, kiId) =>
fetch(
toPath(
URL_PATH_INSTANCE,
scopeId,
'statuses',
URL_PATH_KI,
kiId,
),
options,
),
// Deploy Pool to Instance / Engine
deployPool: (scopeId, poolId) =>
fetch(toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_DEPLOY, poolId), {
...options,
method: 'POST',
}),
// Undeploy Pool to Instance / Engine
undeployPool: (scopeId, poolId) =>
fetch(toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_DEPLOY, poolId), {
...options,
method: 'DELETE',
}),
// Create New Pool in Instance
newPool: (scopeId, data) =>
fetch(toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_POOL), {
...options,
method: 'POST',
body: JSON.stringify({ ...data }),
}),
// Create New Ki in Instance
newKi: (scopeId, data) =>
fetch(toPath(URL_PATH_INSTANCE, scopeId, URL_PATH_KI), {
...options,
method: 'POST',
body: JSON.stringify({ ...data }),
}),
// Get Pool by Id
pool: (poolId) => fetch(toPath(URL_PATH_POOL, poolId), options),
// Delete Pool by Id
deletePool: (poolId) =>
fetch(toPath(URL_PATH_POOL, poolId), {
...options,
method: 'DELETE',
}),
// Get Kis attached to Pool
poolKis: (poolId) =>
fetch(toPath(URL_PATH_POOL, poolId, URL_PATH_KIS), options),
// Check if Ki is Deployed to Pool
poolKiDeployed: (poolId, kiId) =>
fetch(
toPath(URL_PATH_POOL, poolId, URL_PATH_DEPLOYED, kiId),
options,
),
// Deploy Ki to Pool
deployKi: (poolId, kiId) =>
fetch(toPath(URL_PATH_POOL, poolId, URL_PATH_DEPLOY, kiId), {
...options,
method: 'POST',
}),
// Undeploy Ki to Pool
undeployKi: (poolId, kiId) =>
fetch(toPath(URL_PATH_POOL, poolId, URL_PATH_DEPLOY, kiId), {
...options,
method: 'DELETE',
}),
// Get Ki by Id
ki: (kiId) => fetch(toPath(URL_PATH_KI, kiId), options),
// Get Ki History by Id
kiHistory: (kiId) =>
fetch(toPath(URL_PATH_KI, kiId, URL_PATH_HISTORY), options),
// Get Ki History by Id and Version
kiHistoryVersion: (kiId, version) =>
fetch(
toPath(URL_PATH_KI, kiId, URL_PATH_HISTORY, version),
options,
),
updateKi: (kiId, data) =>
fetch(toPath(URL_PATH_KI, kiId), {
...options,
method: 'POST',
body: JSON.stringify({ ...data }),
}),
// Delete Ki by Id
deleteKi: (kiId) =>
fetch(toPath(URL_PATH_KI, kiId), {
...options,
method: 'DELETE',
}),
kiDeployments: (kiId) =>
fetch(toPath(URL_PATH_KI, kiId, 'deployments'), options),
};
}