@raclettejs/core 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE.md +661 -1
- package/dist/cli.js +5 -5
- package/package.json +1 -1
- package/services/backend/src/core/crud/crudTypes.ts +5 -5
- package/services/backend/src/core/payload/payloadRegistrar.ts +15 -15
- package/services/backend/src/core/payload/payloadTypes.ts +4 -4
- package/services/backend/src/core/pluginSystem/pluginFastifyInstance.ts +8 -5
- package/services/backend/src/core/pluginSystem/pluginTypes.ts +4 -4
- package/services/backend/src/core/sockets/createSystemEventHandlers.ts +18 -16
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/account.service.ts +16 -16
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/events/index.ts +4 -4
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/account/helpers/payload.ts +2 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/composition.service.ts +14 -14
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/events/index.ts +3 -3
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/composition/helpers/payload.ts +2 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/events/index.ts +3 -3
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/helpers/payload.ts +2 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/interactionLink/interactionLink.service.ts +18 -18
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/events/index.ts +4 -4
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/helpers/payload.ts +2 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/project/project.service.ts +14 -14
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/events/index.ts +5 -5
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/helpers/payload.ts +2 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/tag/tag.service.ts +14 -14
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/events/index.ts +4 -4
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/helpers/payload.ts +2 -2
- package/services/backend/src/corePlugins/raclette__core/backend/datatypes/user/user.service.ts +14 -14
- package/services/backend/src/modules/cache/cacheManager.ts +4 -4
- package/services/backend/src/types/custom-fastify.d.ts +2 -2
- package/services/backend/src/utils/request.utils.ts +2 -2
- package/services/frontend/src/core/lib/data/dataApi.ts +6 -5
- package/services/frontend/src/core/lib/data/fetchDataHandler.ts +51 -21
- package/services/frontend/src/core/lib/data/queryApi.ts +20 -27
- package/services/frontend/src/core/setup/plugin-system/api/plugin-data.ts +17 -13
- package/services/frontend/src/core/types/DataApi.ts +13 -1
- package/services/frontend/src/orchestrator/composables/useVueQueryObservableHelper.ts +21 -11
- package/services/frontend/src/orchestrator/composables/useVueWriteOperationHelper.ts +27 -18
- package/services/frontend/src/orchestrator/types/PluginApi.ts +7 -3
|
@@ -39,7 +39,7 @@ const requestControllerManager = {
|
|
|
39
39
|
|
|
40
40
|
type ItemDispatcherResultObject = {
|
|
41
41
|
result: Array<Object>
|
|
42
|
-
error
|
|
42
|
+
error?: Object | null
|
|
43
43
|
backendQueryParams?: Object
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -95,13 +95,21 @@ const itemDispatcher = async (
|
|
|
95
95
|
if (resultObj.error) {
|
|
96
96
|
throw resultObj.error
|
|
97
97
|
}
|
|
98
|
-
|
|
98
|
+
$store.dispatch({
|
|
99
|
+
type: "queries/update/loading",
|
|
100
|
+
payload: {
|
|
101
|
+
loading: false,
|
|
102
|
+
actionId: actionId,
|
|
103
|
+
},
|
|
104
|
+
})
|
|
99
105
|
return Promise.resolve(result.map((res) => res._source))
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
// Cache Management Functions
|
|
103
109
|
const cacheOperations = {
|
|
104
|
-
async setupCache(actionId, target, params) {
|
|
110
|
+
async setupCache(actionId, target, params, options) {
|
|
111
|
+
if (options.useStore === false)
|
|
112
|
+
return { cachedQuery: null, actionIdentifier: { actionId } }
|
|
105
113
|
const cachedQuery = getCacheQueryAndHash(target, params)
|
|
106
114
|
const actionIdentifier = {
|
|
107
115
|
actionId,
|
|
@@ -148,7 +156,7 @@ const cacheOperations = {
|
|
|
148
156
|
},
|
|
149
157
|
}
|
|
150
158
|
|
|
151
|
-
const finishRemoteQuery = (actionIdentifier, result, params) => {
|
|
159
|
+
const finishRemoteQuery = (actionIdentifier, result, params, options) => {
|
|
152
160
|
const { actionId, cacheKey } = actionIdentifier
|
|
153
161
|
log.api("finishRemoteQuery", { actionId, params, result })
|
|
154
162
|
|
|
@@ -167,8 +175,15 @@ const finishRemoteQuery = (actionIdentifier, result, params) => {
|
|
|
167
175
|
resultBody.items.forEach((item) => resultObj.result.push(item))
|
|
168
176
|
}
|
|
169
177
|
|
|
170
|
-
if (
|
|
171
|
-
|
|
178
|
+
if (options.useStore === false) {
|
|
179
|
+
$store.dispatch({
|
|
180
|
+
type: "queries/update/loading",
|
|
181
|
+
payload: {
|
|
182
|
+
loading: false,
|
|
183
|
+
actionId: actionId,
|
|
184
|
+
},
|
|
185
|
+
})
|
|
186
|
+
return result.data
|
|
172
187
|
}
|
|
173
188
|
|
|
174
189
|
return itemDispatcher(actionIdentifier, resultObj, true)
|
|
@@ -180,6 +195,7 @@ const handleRemoteRequest = async (
|
|
|
180
195
|
method,
|
|
181
196
|
target,
|
|
182
197
|
params,
|
|
198
|
+
options,
|
|
183
199
|
signal,
|
|
184
200
|
) => {
|
|
185
201
|
const appRequestCode =
|
|
@@ -209,7 +225,7 @@ const handleRemoteRequest = async (
|
|
|
209
225
|
? await $api.axios.get(target, config)
|
|
210
226
|
: await $api.axios.post(target, params, config)
|
|
211
227
|
|
|
212
|
-
return finishRemoteQuery(actionIdentifier, response, params)
|
|
228
|
+
return finishRemoteQuery(actionIdentifier, response, params, options)
|
|
213
229
|
} catch (e) {
|
|
214
230
|
if (e.name === "AbortError" || e.name === "CanceledError") {
|
|
215
231
|
log.api(`${method} request was cancelled for actionId:`, actionIdentifier)
|
|
@@ -227,6 +243,7 @@ const handleRemoteRequest = async (
|
|
|
227
243
|
actionIdentifier,
|
|
228
244
|
{ data: [], error: e?.response?.data || e },
|
|
229
245
|
params,
|
|
246
|
+
options,
|
|
230
247
|
)
|
|
231
248
|
}
|
|
232
249
|
}
|
|
@@ -234,6 +251,7 @@ const handleRemoteRequest = async (
|
|
|
234
251
|
const searchQuery = async (
|
|
235
252
|
actionIdentifier,
|
|
236
253
|
params,
|
|
254
|
+
options,
|
|
237
255
|
signal,
|
|
238
256
|
target = "auto",
|
|
239
257
|
) => {
|
|
@@ -273,6 +291,7 @@ const searchQuery = async (
|
|
|
273
291
|
"POST",
|
|
274
292
|
"core/find/query",
|
|
275
293
|
query,
|
|
294
|
+
options,
|
|
276
295
|
signal,
|
|
277
296
|
)
|
|
278
297
|
} else {
|
|
@@ -313,43 +332,53 @@ const handlePluginReadRoutes = async (actionId, target, params) => {
|
|
|
313
332
|
|
|
314
333
|
// Route Handler Registry
|
|
315
334
|
const routeHandlers = {
|
|
316
|
-
"remote/get": async (actionIdentifier, target, params, signal) => {
|
|
335
|
+
"remote/get": async (actionIdentifier, target, params, options, signal) => {
|
|
317
336
|
const cleanTarget = target.split("remote/get")[1]
|
|
318
337
|
return handleRemoteRequest(
|
|
319
338
|
actionIdentifier,
|
|
320
339
|
"GET",
|
|
321
340
|
cleanTarget,
|
|
322
341
|
params,
|
|
342
|
+
options,
|
|
323
343
|
signal,
|
|
324
344
|
)
|
|
325
345
|
},
|
|
326
346
|
|
|
327
|
-
"remote/post": async (actionIdentifier, target, params, signal) => {
|
|
347
|
+
"remote/post": async (actionIdentifier, target, params, options, signal) => {
|
|
328
348
|
const cleanTarget = target.split("remote/post")[1]
|
|
329
349
|
return handleRemoteRequest(
|
|
330
350
|
actionIdentifier,
|
|
331
351
|
"POST",
|
|
332
352
|
cleanTarget,
|
|
333
353
|
params,
|
|
354
|
+
options,
|
|
334
355
|
signal,
|
|
335
356
|
)
|
|
336
357
|
},
|
|
337
358
|
|
|
338
|
-
"search/query": async (actionIdentifier, target, params, signal) => {
|
|
359
|
+
"search/query": async (actionIdentifier, target, params, options, signal) => {
|
|
339
360
|
if (params.search?.q === "@showall") {
|
|
340
361
|
const dataState = $store.getState("data")
|
|
341
|
-
return itemDispatcher(
|
|
342
|
-
|
|
343
|
-
|
|
362
|
+
return itemDispatcher(
|
|
363
|
+
actionIdentifier,
|
|
364
|
+
{
|
|
365
|
+
result: Object.values(dataState),
|
|
366
|
+
},
|
|
367
|
+
true,
|
|
368
|
+
)
|
|
344
369
|
}
|
|
345
370
|
|
|
346
|
-
return itemDispatcher(
|
|
347
|
-
|
|
348
|
-
|
|
371
|
+
return itemDispatcher(
|
|
372
|
+
actionIdentifier,
|
|
373
|
+
{
|
|
374
|
+
result: [],
|
|
375
|
+
},
|
|
376
|
+
true,
|
|
377
|
+
)
|
|
349
378
|
},
|
|
350
379
|
}
|
|
351
380
|
|
|
352
|
-
const executeRoute = async (actionIdentifier, validTarget, params) => {
|
|
381
|
+
const executeRoute = async (actionIdentifier, validTarget, params, options) => {
|
|
353
382
|
// Find matching route handler
|
|
354
383
|
for (const [routePrefix, handler] of Object.entries(routeHandlers)) {
|
|
355
384
|
if (validTarget.indexOf(routePrefix) === 0 || validTarget === routePrefix) {
|
|
@@ -362,6 +391,7 @@ const executeRoute = async (actionIdentifier, validTarget, params) => {
|
|
|
362
391
|
actionIdentifier,
|
|
363
392
|
validTarget,
|
|
364
393
|
params,
|
|
394
|
+
options,
|
|
365
395
|
controller.signal,
|
|
366
396
|
)
|
|
367
397
|
requestControllerManager.cleanup(actionIdentifier.actionId)
|
|
@@ -386,7 +416,7 @@ const executeRoute = async (actionIdentifier, validTarget, params) => {
|
|
|
386
416
|
throw new Error(`No route handler found for target: ${validTarget}`)
|
|
387
417
|
}
|
|
388
418
|
|
|
389
|
-
const getData = async (actionId, target, params) => {
|
|
419
|
+
const getData = async (actionId, target, params, options) => {
|
|
390
420
|
if (!target) {
|
|
391
421
|
return log.api("getData", "no target given", params)
|
|
392
422
|
}
|
|
@@ -399,10 +429,11 @@ const getData = async (actionId, target, params) => {
|
|
|
399
429
|
actionId,
|
|
400
430
|
validTarget,
|
|
401
431
|
params,
|
|
432
|
+
options,
|
|
402
433
|
)
|
|
403
434
|
|
|
404
435
|
// Check cache
|
|
405
|
-
if (cachedQuery
|
|
436
|
+
if (cachedQuery?.query) {
|
|
406
437
|
const cacheResult = await cacheOperations.handleCacheHit(
|
|
407
438
|
cachedQuery,
|
|
408
439
|
actionIdentifier,
|
|
@@ -411,9 +442,8 @@ const getData = async (actionId, target, params) => {
|
|
|
411
442
|
return cacheResult
|
|
412
443
|
}
|
|
413
444
|
}
|
|
414
|
-
|
|
415
445
|
// Execute route
|
|
416
|
-
return executeRoute(actionIdentifier, validTarget, params)
|
|
446
|
+
return executeRoute(actionIdentifier, validTarget, params, options)
|
|
417
447
|
}
|
|
418
448
|
|
|
419
449
|
export default getData
|
|
@@ -6,6 +6,7 @@ import { fixQueryParamTypes } from "@racletteCore/lib/dataHelper"
|
|
|
6
6
|
import { $store, $eventbus } from "@racletteCore"
|
|
7
7
|
import type { CustomStoreActionsPayload } from "@racletteCore/types"
|
|
8
8
|
import { BehaviorSubject } from "rxjs"
|
|
9
|
+
import { mergeDeepRight, clone } from "ramda"
|
|
9
10
|
|
|
10
11
|
const queryApis = {}
|
|
11
12
|
|
|
@@ -17,15 +18,12 @@ export const $queryApi = (
|
|
|
17
18
|
if (queryApis[actionId] && !target.length) {
|
|
18
19
|
return queryApis[actionId]
|
|
19
20
|
}
|
|
21
|
+
const errorSubject$ = new BehaviorSubject(null)
|
|
22
|
+
const resultSubject$ = new BehaviorSubject({})
|
|
20
23
|
const cleanedParams = fixQueryParamTypes(params)
|
|
21
|
-
|
|
22
|
-
if (params.stateless === true) {
|
|
23
|
-
return getData(actionId, target, cleanedParams)
|
|
24
|
-
}
|
|
25
24
|
// check if we have a query fullfilling the needs of the one requested
|
|
26
25
|
// here. If not we will update the one with this actionId
|
|
27
26
|
let actionType = "queries/add"
|
|
28
|
-
const errorSubject$ = new BehaviorSubject(null)
|
|
29
27
|
|
|
30
28
|
$store.dispatch({
|
|
31
29
|
type: actionType,
|
|
@@ -37,6 +35,9 @@ export const $queryApi = (
|
|
|
37
35
|
})
|
|
38
36
|
const queryApi = {
|
|
39
37
|
error$: errorSubject$.asObservable(),
|
|
38
|
+
result$: resultSubject$.asObservable(),
|
|
39
|
+
query$: $store.select((state) => state.queries[actionId]),
|
|
40
|
+
uuids$: $store.select((state) => state.queries[actionId].uuids),
|
|
40
41
|
remove: () => {
|
|
41
42
|
$store.dispatch({
|
|
42
43
|
type: "queries/remove",
|
|
@@ -45,18 +46,10 @@ export const $queryApi = (
|
|
|
45
46
|
errorSubject$.complete()
|
|
46
47
|
},
|
|
47
48
|
execute: async (executeParams = {}) => {
|
|
49
|
+
const _executeParams = clone(executeParams)
|
|
48
50
|
errorSubject$.next(null)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
$store.dispatch({
|
|
52
|
-
type: "queries/update",
|
|
53
|
-
payload: {
|
|
54
|
-
params: executeParams,
|
|
55
|
-
reset: true,
|
|
56
|
-
actionId: actionId,
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
}
|
|
51
|
+
resultSubject$.next({})
|
|
52
|
+
const queryParams = mergeDeepRight(cleanedParams, _executeParams)
|
|
60
53
|
$store.dispatch({
|
|
61
54
|
type: "queries/update/loading",
|
|
62
55
|
payload: {
|
|
@@ -64,15 +57,17 @@ export const $queryApi = (
|
|
|
64
57
|
actionId: actionId,
|
|
65
58
|
},
|
|
66
59
|
})
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
|
|
61
|
+
const resultData = await getData(
|
|
62
|
+
actionId,
|
|
63
|
+
target,
|
|
64
|
+
queryParams,
|
|
65
|
+
options,
|
|
66
|
+
).catch((e) => {
|
|
67
|
+
const errorObj = e
|
|
68
|
+
errorSubject$.next(errorObj)
|
|
69
|
+
})
|
|
70
|
+
resultSubject$.next(resultData)
|
|
76
71
|
if (options.cb && typeof options.cb === "function") {
|
|
77
72
|
options.cb(resultData)
|
|
78
73
|
}
|
|
@@ -85,8 +80,6 @@ export const $queryApi = (
|
|
|
85
80
|
})
|
|
86
81
|
}
|
|
87
82
|
},
|
|
88
|
-
query$: $store.select((state) => state.queries[actionId]),
|
|
89
|
-
uuids$: $store.select((state) => state.queries[actionId].uuids),
|
|
90
83
|
}
|
|
91
84
|
if (options.immediate === true) {
|
|
92
85
|
queryApi.execute()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getInstanceActionId } from "@shared/helper/pluginHelper"
|
|
2
2
|
import { i18nInstance } from "@racletteOrchestrator"
|
|
3
3
|
import { v4 as uuidv4 } from "uuid"
|
|
4
|
+
import { nanoid } from "nanoid"
|
|
4
5
|
import type { Plugin } from "vue"
|
|
5
6
|
import type {
|
|
6
7
|
CustomStoreActionsPayload,
|
|
@@ -76,15 +77,17 @@ export const handlePluginOperations =
|
|
|
76
77
|
if (actionIdOverride.length) actionIdBase = actionIdOverride
|
|
77
78
|
const actionId = createPluginActionId(dataTypeName, actionIdBase)
|
|
78
79
|
storeActionTypeStoreActions[customOperationName] = ({
|
|
80
|
+
id = nanoid(4),
|
|
79
81
|
params = {},
|
|
80
82
|
options = {},
|
|
81
83
|
}: CustomStoreActionsPayload = {}) => {
|
|
82
|
-
const instanceActionId =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
const instanceActionId =
|
|
85
|
+
getInstanceActionId(
|
|
86
|
+
prefixedPluginName,
|
|
87
|
+
instanceId,
|
|
88
|
+
actionId,
|
|
89
|
+
actionIdOverride,
|
|
90
|
+
) + `-${id}`
|
|
88
91
|
if (!params._id && options.immediate === true) {
|
|
89
92
|
params._id = uuidv4()
|
|
90
93
|
}
|
|
@@ -108,15 +111,17 @@ export const handlePluginOperations =
|
|
|
108
111
|
const actionId = createPluginActionId(dataTypeName, actionIdBase)
|
|
109
112
|
|
|
110
113
|
storeActionTypeStoreActions[customOperationName] = ({
|
|
114
|
+
id = nanoid(4),
|
|
111
115
|
params = {},
|
|
112
116
|
options = {},
|
|
113
117
|
}: CustomStoreActionsPayload = {}) => {
|
|
114
|
-
const instanceActionId =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
const instanceActionId =
|
|
119
|
+
getInstanceActionId(
|
|
120
|
+
prefixedPluginName,
|
|
121
|
+
instanceId,
|
|
122
|
+
actionId,
|
|
123
|
+
actionIdOverride,
|
|
124
|
+
) + `-${id}`
|
|
120
125
|
const method = customOperation.method || "get"
|
|
121
126
|
let target = handleOperationTarget(customOperation.target, params)
|
|
122
127
|
|
|
@@ -130,7 +135,6 @@ export const handlePluginOperations =
|
|
|
130
135
|
}
|
|
131
136
|
// todo remove this singleton and pass the operationConfig to the query state as we need it in the fetch handler, also if it is called by the query effect
|
|
132
137
|
addPluginReadOperation(instanceActionId, operationConfig)
|
|
133
|
-
|
|
134
138
|
return orchestratorResultWrapper.read(instanceActionId, target, {
|
|
135
139
|
params,
|
|
136
140
|
options,
|
|
@@ -10,9 +10,21 @@ export type CustomStoreActionOptions = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export type CustomStoreActionsPayload = {
|
|
13
|
+
id?: String // if set this will used as the final namespace giver for the actionId, if not it will be a nanoId
|
|
13
14
|
params?: CustomStoreActionParams
|
|
14
15
|
options?: CustomStoreActionOptions
|
|
15
16
|
}
|
|
16
17
|
export type QueryApiQuery = QueryState & {
|
|
17
|
-
execute: (params?: Record<string, any>) =>
|
|
18
|
+
execute: (params?: Record<string, any>) => Promise<any>
|
|
19
|
+
}
|
|
20
|
+
export type DataApiMethods = {
|
|
21
|
+
data: Object
|
|
22
|
+
error: Object
|
|
23
|
+
response: Object
|
|
24
|
+
isLoading: Boolean
|
|
25
|
+
execute: Function
|
|
26
|
+
}
|
|
27
|
+
export type QueryMethods = DataApiMethods & {
|
|
28
|
+
uuids: Array<string>
|
|
29
|
+
query: Object
|
|
18
30
|
}
|
|
@@ -4,6 +4,7 @@ import { $queryApi } from "@racletteCore/lib/data/dataApi"
|
|
|
4
4
|
import type {
|
|
5
5
|
CustomStoreActionsPayload,
|
|
6
6
|
QueryApiQuery,
|
|
7
|
+
QueryMethods,
|
|
7
8
|
} from "@racletteCore/types"
|
|
8
9
|
import { difference } from "ramda"
|
|
9
10
|
import getStateObservable from "@racletteCore/lib/observableHelpers/getStateObservable"
|
|
@@ -16,7 +17,7 @@ export const useVueQueryObservableHelper = (
|
|
|
16
17
|
instanceActionId,
|
|
17
18
|
target,
|
|
18
19
|
{ params = {}, options = {} }: CustomStoreActionsPayload = {},
|
|
19
|
-
) => {
|
|
20
|
+
): QueryMethods => {
|
|
20
21
|
const dataObservable$ = ref<Observable<unknown>>()
|
|
21
22
|
|
|
22
23
|
const data = computed(() => {
|
|
@@ -40,17 +41,24 @@ export const useVueQueryObservableHelper = (
|
|
|
40
41
|
subscriber$[instanceActionId] = coreQuery
|
|
41
42
|
const queryRef = useObservable<QueryApiQuery>(coreQuery.query$)
|
|
42
43
|
const errorObservable = useObservable(coreQuery.error$)
|
|
44
|
+
const resultRef = useObservable<QueryApiQuery>(coreQuery.result$)
|
|
45
|
+
if (options.useStore !== false) {
|
|
46
|
+
watch(queryRef, (value, oldValue) => {
|
|
47
|
+
const newUUIDS = value?.uuids || []
|
|
48
|
+
const oldUUIDS = oldValue?.uuids || []
|
|
49
|
+
if (
|
|
50
|
+
difference(newUUIDS, oldUUIDS).length ||
|
|
51
|
+
difference(oldUUIDS || [], newUUIDS).length
|
|
52
|
+
) {
|
|
53
|
+
dataObservable$.value = getStateObservable([
|
|
54
|
+
"data",
|
|
55
|
+
newUUIDS,
|
|
56
|
+
"_source",
|
|
57
|
+
])
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}
|
|
43
61
|
|
|
44
|
-
watch(queryRef, (value, oldValue) => {
|
|
45
|
-
const newUUIDS = value?.uuids || []
|
|
46
|
-
const oldUUIDS = oldValue?.uuids || []
|
|
47
|
-
if (
|
|
48
|
-
difference(newUUIDS, oldUUIDS).length ||
|
|
49
|
-
difference(oldUUIDS || [], newUUIDS).length
|
|
50
|
-
) {
|
|
51
|
-
dataObservable$.value = getStateObservable(["data", newUUIDS, "_source"])
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
62
|
onUnmounted(() => {
|
|
55
63
|
subscriberCounter[instanceActionId] -= 1
|
|
56
64
|
if (subscriberCounter[instanceActionId] === 0) {
|
|
@@ -65,11 +73,13 @@ export const useVueQueryObservableHelper = (
|
|
|
65
73
|
return queryRef.value?.loading
|
|
66
74
|
}),
|
|
67
75
|
data,
|
|
76
|
+
response: resultRef,
|
|
68
77
|
execute: coreQuery.execute,
|
|
69
78
|
uuids: coreQuery.uuids$,
|
|
70
79
|
error: computed(() => {
|
|
71
80
|
return errorObservable.value
|
|
72
81
|
}),
|
|
73
82
|
}
|
|
83
|
+
if (options.useStore === false) delete queryObject.uuids
|
|
74
84
|
return queryObject
|
|
75
85
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { computed, ref, watch, onUnmounted } from "vue"
|
|
2
2
|
import { useObservable } from "@vueuse/rxjs"
|
|
3
3
|
import { $writeDataApi } from "@racletteCore/lib/data/dataApi"
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
CustomStoreActionsPayload,
|
|
6
|
+
DataApiMethods,
|
|
7
|
+
} from "@racletteCore/types"
|
|
5
8
|
import getStateObservable from "@racletteCore/lib/observableHelpers/getStateObservable"
|
|
6
9
|
import type { Observable } from "rxjs"
|
|
7
10
|
|
|
@@ -12,10 +15,11 @@ export const useVueWriteOperationHelper = (
|
|
|
12
15
|
instanceActionId,
|
|
13
16
|
operationDefinition,
|
|
14
17
|
{ params = {}, options = {} }: CustomStoreActionsPayload = {},
|
|
15
|
-
) => {
|
|
18
|
+
): DataApiMethods => {
|
|
16
19
|
let writeOperation
|
|
17
|
-
const dataStoreObservable$ = ref<Observable<
|
|
18
|
-
|
|
20
|
+
const dataStoreObservable$ = ref<Observable<any>>()
|
|
21
|
+
|
|
22
|
+
const data = computed(() => {
|
|
19
23
|
if (dataStoreObservable$.value) {
|
|
20
24
|
const result = useObservable(dataStoreObservable$.value).value
|
|
21
25
|
return result
|
|
@@ -23,6 +27,7 @@ export const useVueWriteOperationHelper = (
|
|
|
23
27
|
|
|
24
28
|
return null
|
|
25
29
|
})
|
|
30
|
+
|
|
26
31
|
if (subscriber$[instanceActionId]) {
|
|
27
32
|
subscriberCounter[instanceActionId] += 1
|
|
28
33
|
writeOperation = subscriber$[instanceActionId]
|
|
@@ -40,6 +45,22 @@ export const useVueWriteOperationHelper = (
|
|
|
40
45
|
const isLoadingObservable = useObservable(writeOperation.isLoading$)
|
|
41
46
|
const dataObservable = useObservable(writeOperation.data$)
|
|
42
47
|
const errorObservable = useObservable(writeOperation.error$)
|
|
48
|
+
const resultRef = useObservable(writeOperation.result$)
|
|
49
|
+
if (options.useStore !== false) {
|
|
50
|
+
watch(dataObservable, (value, oldValue) => {
|
|
51
|
+
const uuids = []
|
|
52
|
+
if (dataObservable.value && Array.isArray(dataObservable.value)) {
|
|
53
|
+
dataObservable.value.forEach((item) => {
|
|
54
|
+
uuids.push(item._id)
|
|
55
|
+
})
|
|
56
|
+
dataStoreObservable$.value = getStateObservable([
|
|
57
|
+
"data",
|
|
58
|
+
uuids,
|
|
59
|
+
"_source",
|
|
60
|
+
])
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}
|
|
43
64
|
|
|
44
65
|
onUnmounted(() => {
|
|
45
66
|
subscriberCounter[instanceActionId] -= 1
|
|
@@ -58,20 +79,8 @@ export const useVueWriteOperationHelper = (
|
|
|
58
79
|
isLoading: computed(() => {
|
|
59
80
|
return isLoadingObservable.value
|
|
60
81
|
}),
|
|
61
|
-
data
|
|
62
|
-
|
|
63
|
-
if (dataObservable.value && Array.isArray(dataObservable.value)) {
|
|
64
|
-
dataObservable.value.forEach((item) => {
|
|
65
|
-
uuids.push(item._id)
|
|
66
|
-
})
|
|
67
|
-
dataStoreObservable$.value = getStateObservable([
|
|
68
|
-
"data",
|
|
69
|
-
uuids,
|
|
70
|
-
"_source",
|
|
71
|
-
])
|
|
72
|
-
}
|
|
73
|
-
return storeData.value || []
|
|
74
|
-
}),
|
|
82
|
+
data,
|
|
83
|
+
response: resultRef,
|
|
75
84
|
execute: writeOperation.execute,
|
|
76
85
|
error: computed(() => {
|
|
77
86
|
return errorObservable.value
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { useI18n } from "vue-i18n"
|
|
2
|
-
import type { ComputedRef } from "vue"
|
|
2
|
+
import type { ComputedRef, Ref } from "vue"
|
|
3
3
|
import type { CorePluginApi } from "@racletteCore/main"
|
|
4
4
|
import type {
|
|
5
5
|
CustomStoreActionsPayload,
|
|
@@ -11,11 +11,15 @@ import type { Socket } from "socket.io-client"
|
|
|
11
11
|
import type { User } from "@shared/types"
|
|
12
12
|
// TODO: finalize types
|
|
13
13
|
// TODO: generate this type from index.ts in the plugin & extend it globally
|
|
14
|
-
|
|
15
14
|
export type PluginMethod = (payload?: CustomStoreActionsPayload) => {
|
|
16
|
-
|
|
15
|
+
isLoading: Boolean
|
|
16
|
+
response: Ref<unknown>
|
|
17
|
+
error: Ref<unknown>
|
|
17
18
|
data: ComputedRef<unknown>
|
|
18
19
|
execute: (params?: Record<string, any>) => void
|
|
20
|
+
// query and uuids only provided from queryObservableHelper
|
|
21
|
+
query?: ComputedRef<Query>
|
|
22
|
+
uuids?: Array<string>
|
|
19
23
|
// TODO: implement this in the useVueQueryObservableHelper remove: () => void
|
|
20
24
|
}
|
|
21
25
|
export type PluginSocketApi = {
|