@judo/actions 0.1.0
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/LICENSE +277 -0
- package/README.md +257 -0
- package/dist/api/constants.d.ts +27 -0
- package/dist/api/constants.d.ts.map +1 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/judo-rest-api.d.ts +262 -0
- package/dist/api/judo-rest-api.d.ts.map +1 -0
- package/dist/api/model-converters.d.ts +29 -0
- package/dist/api/model-converters.d.ts.map +1 -0
- package/dist/api/path-builder.d.ts +50 -0
- package/dist/api/path-builder.d.ts.map +1 -0
- package/dist/api/transfer-deserializer.d.ts +46 -0
- package/dist/api/transfer-deserializer.d.ts.map +1 -0
- package/dist/api/transfer-serializer.d.ts +85 -0
- package/dist/api/transfer-serializer.d.ts.map +1 -0
- package/dist/api/types.d.ts +278 -0
- package/dist/api/types.d.ts.map +1 -0
- package/dist/handlers/autocomplete/autocomplete-handlers.d.ts +20 -0
- package/dist/handlers/autocomplete/autocomplete-handlers.d.ts.map +1 -0
- package/dist/handlers/autocomplete/index.d.ts +2 -0
- package/dist/handlers/autocomplete/index.d.ts.map +1 -0
- package/dist/handlers/crud/crud-handlers.d.ts +76 -0
- package/dist/handlers/crud/crud-handlers.d.ts.map +1 -0
- package/dist/handlers/crud/index.d.ts +2 -0
- package/dist/handlers/crud/index.d.ts.map +1 -0
- package/dist/handlers/form/form-handlers.d.ts +28 -0
- package/dist/handlers/form/form-handlers.d.ts.map +1 -0
- package/dist/handlers/form/index.d.ts +2 -0
- package/dist/handlers/form/index.d.ts.map +1 -0
- package/dist/handlers/index.d.ts +10 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/navigation/index.d.ts +2 -0
- package/dist/handlers/navigation/index.d.ts.map +1 -0
- package/dist/handlers/navigation/navigation-handlers.d.ts +23 -0
- package/dist/handlers/navigation/navigation-handlers.d.ts.map +1 -0
- package/dist/handlers/operation/index.d.ts +2 -0
- package/dist/handlers/operation/index.d.ts.map +1 -0
- package/dist/handlers/operation/operation-handlers.d.ts +43 -0
- package/dist/handlers/operation/operation-handlers.d.ts.map +1 -0
- package/dist/handlers/other/index.d.ts +2 -0
- package/dist/handlers/other/index.d.ts.map +1 -0
- package/dist/handlers/other/other-handlers.d.ts +10 -0
- package/dist/handlers/other/other-handlers.d.ts.map +1 -0
- package/dist/handlers/relation/index.d.ts +2 -0
- package/dist/handlers/relation/index.d.ts.map +1 -0
- package/dist/handlers/relation/relation-handlers.d.ts +49 -0
- package/dist/handlers/relation/relation-handlers.d.ts.map +1 -0
- package/dist/handlers/selector/index.d.ts +2 -0
- package/dist/handlers/selector/index.d.ts.map +1 -0
- package/dist/handlers/selector/selector-handlers.d.ts +30 -0
- package/dist/handlers/selector/selector-handlers.d.ts.map +1 -0
- package/dist/handlers/table/index.d.ts +2 -0
- package/dist/handlers/table/index.d.ts.map +1 -0
- package/dist/handlers/table/table-handlers.d.ts +18 -0
- package/dist/handlers/table/table-handlers.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-action-dispatcher.d.ts +61 -0
- package/dist/hooks/use-action-dispatcher.d.ts.map +1 -0
- package/dist/hooks/use-action-handler.d.ts +29 -0
- package/dist/hooks/use-action-handler.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1427 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle/execute-with-lifecycle.d.ts +20 -0
- package/dist/lifecycle/execute-with-lifecycle.d.ts.map +1 -0
- package/dist/lifecycle/index.d.ts +2 -0
- package/dist/lifecycle/index.d.ts.map +1 -0
- package/dist/provider/api-context.d.ts +30 -0
- package/dist/provider/api-context.d.ts.map +1 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.d.ts.map +1 -0
- package/dist/registry/action-handler-registry.d.ts +11 -0
- package/dist/registry/action-handler-registry.d.ts.map +1 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/types-BsQmyhQI.js +14 -0
- package/dist/types-BsQmyhQI.js.map +1 -0
- package/dist/types-CbA9-fcJ.js +2 -0
- package/dist/types.d.ts +260 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +45 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1427 @@
|
|
|
1
|
+
import { t as ValidationError } from "./types-BsQmyhQI.js";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var RelationBehaviourType = {
|
|
5
|
+
LIST: "LIST",
|
|
6
|
+
CREATE: "CREATE",
|
|
7
|
+
SET: "SET",
|
|
8
|
+
UNSET: "UNSET",
|
|
9
|
+
ADD: "ADD",
|
|
10
|
+
REMOVE: "REMOVE",
|
|
11
|
+
RANGE: "RANGE",
|
|
12
|
+
VALIDATE_CREATE: "VALIDATE_CREATE",
|
|
13
|
+
TEMPLATE: "TEMPLATE",
|
|
14
|
+
UPDATE: "UPDATE",
|
|
15
|
+
VALIDATE_UPDATE: "VALIDATE_UPDATE",
|
|
16
|
+
DELETE: "DELETE",
|
|
17
|
+
REFRESH: "REFRESH",
|
|
18
|
+
EXPORT: "EXPORT"
|
|
19
|
+
}, ACTION_HANDLER_FACTORY = Symbol.for("@judo/ACTION_HANDLER_FACTORY");
|
|
20
|
+
const useBackActionHandler = ((o) => async (o) => {
|
|
21
|
+
if (o.closeDialog) {
|
|
22
|
+
o.closeDialog();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
o.navigation.goBack();
|
|
26
|
+
});
|
|
27
|
+
useBackActionHandler.actionType = "BackActionDefinition";
|
|
28
|
+
const useOpenPageActionHandler = ((o) => async (F) => {
|
|
29
|
+
let I = o.targetPageDefinition;
|
|
30
|
+
if (!I) throw Error("No target page defined for OpenPageAction");
|
|
31
|
+
if (!F.navigation) throw Error("Navigation context is undefined");
|
|
32
|
+
let L = F;
|
|
33
|
+
F.navigation.navigateTo(I, {
|
|
34
|
+
transfer: F.transfer,
|
|
35
|
+
...F.isEager && {
|
|
36
|
+
isEager: !0,
|
|
37
|
+
parentTransferId: L.parentTransferId,
|
|
38
|
+
relationName: L.relationName
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
useOpenPageActionHandler.actionType = "OpenPageActionDefinition";
|
|
43
|
+
const useRowOpenPageActionHandler = ((o) => async (F) => {
|
|
44
|
+
let I = o.targetPageDefinition;
|
|
45
|
+
if (!I) throw Error("No target page defined for RowOpenPageAction");
|
|
46
|
+
if (!F.navigation) throw Error("Navigation context is undefined");
|
|
47
|
+
let L = F;
|
|
48
|
+
F.navigation.navigateTo(I, {
|
|
49
|
+
transfer: F.transfer,
|
|
50
|
+
...F.isEager && {
|
|
51
|
+
isEager: !0,
|
|
52
|
+
parentTransferId: L.parentTransferId,
|
|
53
|
+
relationName: L.relationName
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
useRowOpenPageActionHandler.actionType = "RowOpenPageActionDefinition";
|
|
58
|
+
const useCancelActionHandler = ((o) => async (o) => {
|
|
59
|
+
if (o.closeDialog) {
|
|
60
|
+
o.closeDialog();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (o.pageType === "VIEW" && o.isEditMode && o.data && o.transfer?.__identifier) {
|
|
64
|
+
o.data.resetTransfer(o.transfer.__identifier);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
o.navigation.goBack();
|
|
68
|
+
});
|
|
69
|
+
useCancelActionHandler.actionType = "CancelActionDefinition";
|
|
70
|
+
const useOpenFormActionHandler = ((o) => async (F) => {
|
|
71
|
+
let I = o.targetPageDefinition;
|
|
72
|
+
if (!I) throw Error("No target page defined for OpenFormAction");
|
|
73
|
+
F.navigation.openDialog(I, { transfer: F.transfer });
|
|
74
|
+
});
|
|
75
|
+
useOpenFormActionHandler.actionType = "OpenFormActionDefinition";
|
|
76
|
+
const useOpenCreateFormActionHandler = ((o) => async (F) => {
|
|
77
|
+
let I = o.targetPageDefinition;
|
|
78
|
+
if (!I) throw Error("No target page defined for OpenCreateFormAction");
|
|
79
|
+
let L = o.ownerDataElement, R = F.isEager === !0, z = F.transfer, B = F;
|
|
80
|
+
F.navigation.openDialog(I, {
|
|
81
|
+
isCreate: !0,
|
|
82
|
+
isEager: R,
|
|
83
|
+
relation: L,
|
|
84
|
+
ownerTransfer: z,
|
|
85
|
+
...R && {
|
|
86
|
+
parentTransferId: B.parentTransferId,
|
|
87
|
+
relationName: B.relationName,
|
|
88
|
+
onSubmitCreate: async (o) => o
|
|
89
|
+
}
|
|
90
|
+
}, B.onDialogClose);
|
|
91
|
+
});
|
|
92
|
+
useOpenCreateFormActionHandler.actionType = "OpenCreateFormActionDefinition";
|
|
93
|
+
const useOpenOperationInputFormActionHandler = ((o) => async (F) => {
|
|
94
|
+
let I = o.targetPageDefinition;
|
|
95
|
+
if (!I) throw Error("No target page defined for OpenOperationInputFormAction");
|
|
96
|
+
F.navigation.openDialog(I, {
|
|
97
|
+
transfer: F.transfer,
|
|
98
|
+
operation: o.actionDefinition.formFor?.operation,
|
|
99
|
+
isOperationInput: !0
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
useOpenOperationInputFormActionHandler.actionType = "OpenOperationInputFormActionDefinition";
|
|
103
|
+
function getRelation$3(o, F) {
|
|
104
|
+
if (o.relation) return o.relation;
|
|
105
|
+
let I = F.ownerDataElement;
|
|
106
|
+
return I && I["@type"] === "RelationType" ? I : null;
|
|
107
|
+
}
|
|
108
|
+
const useOpenSelectorActionHandler = ((o) => async (F) => {
|
|
109
|
+
let I = o.targetPageDefinition;
|
|
110
|
+
if (!I) throw Error("No target page defined for OpenSelectorAction");
|
|
111
|
+
F.navigation?.openDialog(I, {
|
|
112
|
+
ownerTransfer: F.transfer,
|
|
113
|
+
isSelector: !0,
|
|
114
|
+
selectionMode: "single"
|
|
115
|
+
}, F.onDialogClose);
|
|
116
|
+
});
|
|
117
|
+
useOpenSelectorActionHandler.actionType = "OpenSelectorActionDefinition";
|
|
118
|
+
const useOpenAddSelectorActionHandler = ((o) => async (F) => {
|
|
119
|
+
let I = o.targetPageDefinition;
|
|
120
|
+
if (!I) throw Error("No target page defined for OpenAddSelectorAction");
|
|
121
|
+
F.navigation?.openDialog(I, {
|
|
122
|
+
ownerTransfer: F.transfer,
|
|
123
|
+
isSelector: !0,
|
|
124
|
+
selectionMode: "multiple",
|
|
125
|
+
operation: "add"
|
|
126
|
+
}, F.onDialogClose);
|
|
127
|
+
});
|
|
128
|
+
useOpenAddSelectorActionHandler.actionType = "OpenAddSelectorActionDefinition";
|
|
129
|
+
const useOpenSetSelectorActionHandler = ((o) => async (F) => {
|
|
130
|
+
let I = o.targetPageDefinition;
|
|
131
|
+
if (!I) throw Error("No target page defined for OpenSetSelectorAction");
|
|
132
|
+
F.navigation?.openDialog(I, {
|
|
133
|
+
ownerTransfer: F.transfer,
|
|
134
|
+
isSelector: !0,
|
|
135
|
+
selectionMode: "single",
|
|
136
|
+
operation: "set"
|
|
137
|
+
}, F.onDialogClose);
|
|
138
|
+
});
|
|
139
|
+
useOpenSetSelectorActionHandler.actionType = "OpenSetSelectorActionDefinition";
|
|
140
|
+
const useOpenOperationInputSelectorActionHandler = ((o) => async (F) => {
|
|
141
|
+
let I = o.targetPageDefinition;
|
|
142
|
+
if (!I) throw Error("No target page defined for OpenOperationInputSelectorAction");
|
|
143
|
+
let { refreshPage: L, isEditMode: R } = F;
|
|
144
|
+
F.navigation?.openDialog(I, {
|
|
145
|
+
ownerTransfer: F.transfer,
|
|
146
|
+
isSelector: !0,
|
|
147
|
+
isOperationInput: !0
|
|
148
|
+
}, (o) => {
|
|
149
|
+
o?.type === "submitted" && !R && L?.();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
useOpenOperationInputSelectorActionHandler.actionType = "OpenOperationInputSelectorActionDefinition";
|
|
153
|
+
const useSelectorRangeActionHandler = ((o) => async (F) => {
|
|
154
|
+
let I = o.actionDefinition.targetType;
|
|
155
|
+
if (!I) throw Error("No target type defined for SelectorRangeAction");
|
|
156
|
+
let L = F, { onRangeRequest: R, api: z, onRangeResult: B } = L;
|
|
157
|
+
if (R) {
|
|
158
|
+
R(I);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (z) {
|
|
162
|
+
let F = getRelation$3(L, o);
|
|
163
|
+
if (!F) throw Error("Cannot determine relation for selector range");
|
|
164
|
+
let I = await z.getRelationRange(F, L.ownerTransfer, L.queryCustomizer);
|
|
165
|
+
B?.(I.data);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
useSelectorRangeActionHandler.actionType = "SelectorRangeActionDefinition";
|
|
169
|
+
function isValidationError$1(o) {
|
|
170
|
+
return typeof o == "object" && !!o && o.name === "ValidationError";
|
|
171
|
+
}
|
|
172
|
+
function resolveTargetClassType(o) {
|
|
173
|
+
let F = o.actionDefinition?.targetType;
|
|
174
|
+
if (F) return F;
|
|
175
|
+
let I = o.eContainer;
|
|
176
|
+
if (!I?.dataElement) return;
|
|
177
|
+
let L = I.dataElement;
|
|
178
|
+
if (L["@type"] === "ClassType" || L["@type"] === "data:ClassType") return L;
|
|
179
|
+
if (L["@type"] === "RelationType" || L["@type"] === "data:RelationType" || L.target) return L.target;
|
|
180
|
+
}
|
|
181
|
+
function isAccessRelationListAction(o, F) {
|
|
182
|
+
let I = o.ownerDataElement;
|
|
183
|
+
if (!I || I["@type"] !== "RelationType") return !1;
|
|
184
|
+
let L = I;
|
|
185
|
+
return String(L.isAccess) === "true" && !F?.__identifier && !F?.__signedIdentifier;
|
|
186
|
+
}
|
|
187
|
+
function isEntityRelationListAction(o, F) {
|
|
188
|
+
let I = o.ownerDataElement;
|
|
189
|
+
if (!I || I["@type"] !== "RelationType") return !1;
|
|
190
|
+
let L = I;
|
|
191
|
+
return String(L.isAccess) !== "true" && !!F?.__signedIdentifier;
|
|
192
|
+
}
|
|
193
|
+
const useRefreshActionHandler = ((o) => async (F) => {
|
|
194
|
+
let I = F.transfer, L = F, { api: R, pageTransferId: z, rowsPerPage: B } = L, V = o.queryCustomizer, H = o.countRecords;
|
|
195
|
+
if (isAccessRelationListAction(o, I)) {
|
|
196
|
+
let I = o.ownerDataElement, U = z ?? `table::${o["xmi:id"]}`;
|
|
197
|
+
F.data?.setTransferLoading(U, !0);
|
|
198
|
+
try {
|
|
199
|
+
let { onListRelation: o } = L, z;
|
|
200
|
+
if (o) z = await o(I);
|
|
201
|
+
else if (R) {
|
|
202
|
+
let o = {
|
|
203
|
+
_seek: { limit: B ?? 10 },
|
|
204
|
+
...V
|
|
205
|
+
}, L = await R.listRelation(I, void 0, o, H);
|
|
206
|
+
z = L.data;
|
|
207
|
+
let W = L.headers.get("x-judo-count"), G = W ? Number.parseInt(W, 10) : void 0, K = { __items: z };
|
|
208
|
+
G !== void 0 && !Number.isNaN(G) && (K.__totalCount = G), F.data?.setTransferData(U, K);
|
|
209
|
+
} else throw Error("API not available in context");
|
|
210
|
+
} catch (o) {
|
|
211
|
+
throw F.data?.setTransferError(U, o), o;
|
|
212
|
+
} finally {
|
|
213
|
+
F.data?.setTransferLoading(U, !1);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (isEntityRelationListAction(o, I)) {
|
|
218
|
+
let L = o.ownerDataElement, U = z ?? `table::${o["xmi:id"]}`;
|
|
219
|
+
F.data?.setTransferLoading(U, !0);
|
|
220
|
+
try {
|
|
221
|
+
if (R) {
|
|
222
|
+
let o = {
|
|
223
|
+
_seek: { limit: B ?? 10 },
|
|
224
|
+
...V
|
|
225
|
+
}, z = await R.listRelation(L, I, o, H), W = z.data, G = z.headers.get("x-judo-count"), K = G ? Number.parseInt(G, 10) : void 0, q = { __items: W };
|
|
226
|
+
K !== void 0 && !Number.isNaN(K) && (q.__totalCount = K), F.data?.setTransferData(U, q);
|
|
227
|
+
} else throw Error("API not available in context");
|
|
228
|
+
} catch (o) {
|
|
229
|
+
throw F.data?.setTransferError(U, o), o;
|
|
230
|
+
} finally {
|
|
231
|
+
F.data?.setTransferLoading(U, !1);
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (L.isSelector) {
|
|
236
|
+
let I = o.ownerDataElement;
|
|
237
|
+
if (I && I["@type"] === "RelationType") {
|
|
238
|
+
let U = I, W = z ?? `table::${o["xmi:id"]}`;
|
|
239
|
+
F.data?.setTransferLoading(W, !0);
|
|
240
|
+
try {
|
|
241
|
+
if (R) {
|
|
242
|
+
let o = {
|
|
243
|
+
_seek: { limit: B ?? 10 },
|
|
244
|
+
...V
|
|
245
|
+
}, I = await R.getRelationRange(U, L.ownerTransfer?.__signedIdentifier ? { __signedIdentifier: L.ownerTransfer.__signedIdentifier } : void 0, o, H), z = I.data, G = I.headers.get("x-judo-count"), K = G ? Number.parseInt(G, 10) : void 0, q = { __items: z };
|
|
246
|
+
K !== void 0 && !Number.isNaN(K) && (q.__totalCount = K), F.data?.setTransferData(W, q);
|
|
247
|
+
} else throw Error("API not available in context");
|
|
248
|
+
} catch (o) {
|
|
249
|
+
throw F.data?.setTransferError(W, o), o;
|
|
250
|
+
} finally {
|
|
251
|
+
F.data?.setTransferLoading(W, !1);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (I && I["@type"] === "OperationType") {
|
|
256
|
+
let U = I, W = I.eContainer;
|
|
257
|
+
if (!W) throw Error("Cannot determine owning ClassType for operation input selector (OperationType.eContainer is missing)");
|
|
258
|
+
let G = z ?? `table::${o["xmi:id"]}`;
|
|
259
|
+
F.data?.setTransferLoading(G, !0);
|
|
260
|
+
try {
|
|
261
|
+
if (R) {
|
|
262
|
+
let o = {
|
|
263
|
+
_seek: { limit: B ?? 10 },
|
|
264
|
+
...V
|
|
265
|
+
}, I = await R.getOperationInputRange(W, U, L.ownerTransfer?.__signedIdentifier ? { __signedIdentifier: L.ownerTransfer.__signedIdentifier } : void 0, o, H), z = I.data, K = I.headers.get("x-judo-count"), q = K ? Number.parseInt(K, 10) : void 0, J = { __items: z };
|
|
266
|
+
q !== void 0 && !Number.isNaN(q) && (J.__totalCount = q), F.data?.setTransferData(G, J);
|
|
267
|
+
} else throw Error("API not available in context");
|
|
268
|
+
} catch (o) {
|
|
269
|
+
throw F.data?.setTransferError(G, o), o;
|
|
270
|
+
} finally {
|
|
271
|
+
F.data?.setTransferLoading(G, !1);
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
let U = I?.__identifier ?? I?.__signedIdentifier;
|
|
277
|
+
if (U) {
|
|
278
|
+
if (F.isEager) {
|
|
279
|
+
let o = F;
|
|
280
|
+
if (o.parentTransferId && o.relationName && F.data) {
|
|
281
|
+
let L = F.data.getSnapshot((F) => F.transfers.get(o.parentTransferId)?.data);
|
|
282
|
+
if (L) {
|
|
283
|
+
let R = L[o.relationName];
|
|
284
|
+
if (Array.isArray(R)) {
|
|
285
|
+
let o = R.find((o) => {
|
|
286
|
+
if (I.__signedIdentifier && o.__signedIdentifier === I.__signedIdentifier || I.__identifier && o.__identifier === I.__identifier) return !0;
|
|
287
|
+
let F = o.__tempId, L = I?.__tempId;
|
|
288
|
+
return !!(F && L && F === L);
|
|
289
|
+
});
|
|
290
|
+
if (o) {
|
|
291
|
+
F.data.setTransferData(U, o);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
} else if (R && typeof R == "object") {
|
|
295
|
+
F.data.setTransferData(U, R);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
F.data?.setTransferData(U, I);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
F.data?.setTransferLoading(U, !0);
|
|
304
|
+
try {
|
|
305
|
+
let z = resolveTargetClassType(o);
|
|
306
|
+
if (!z) throw Error("No target type for refresh");
|
|
307
|
+
let { onRefresh: B } = L, H;
|
|
308
|
+
if (B) H = await B(U, z);
|
|
309
|
+
else if (R) H = (await R.refresh(z, I, V)).data;
|
|
310
|
+
else throw Error("API not available in context");
|
|
311
|
+
F.data?.setTransferData(U, H);
|
|
312
|
+
} catch (o) {
|
|
313
|
+
throw F.data?.setTransferError(U, o), o;
|
|
314
|
+
} finally {
|
|
315
|
+
F.data?.setTransferLoading(U, !1);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
useRefreshActionHandler.actionType = "RefreshActionDefinition";
|
|
320
|
+
const useCreateActionHandler = ((o) => async (F) => {
|
|
321
|
+
let I = F.transfer;
|
|
322
|
+
if (!I && F.data) {
|
|
323
|
+
let o = F.pageTransferId;
|
|
324
|
+
o && (I = F.data.getSnapshot((F) => F.transfers.get(o)?.data));
|
|
325
|
+
}
|
|
326
|
+
if (!I) throw Error("No transfer data to create");
|
|
327
|
+
let { isEager: L, pageType: R, isEditMode: z, isPageAction: V, validation: H, createDialog: U } = F;
|
|
328
|
+
if (!L && !V) {
|
|
329
|
+
if (R === "FORM") throw Error("Create operation is not allowed on FORM pages. Save the form first.");
|
|
330
|
+
if (R === "VIEW" && z) throw Error("Create operation is not allowed while the view has unsaved changes. Save or cancel changes first.");
|
|
331
|
+
}
|
|
332
|
+
let W = F.pageTransferId ?? I.__identifier ?? "new";
|
|
333
|
+
F.data?.setTransferLoading(W, !0), H?.clearErrors();
|
|
334
|
+
try {
|
|
335
|
+
let { onCreate: R, onValidateCreate: z, api: V, relationMetadata: W, ownerTransfer: G, parentTransferId: K } = F, q;
|
|
336
|
+
o.ownerDataElement?.["@type"] === "RelationType" && (q = o.ownerDataElement), q ||= U?.relation, !q && W && ("relation" in W && W.relation ? q = W.relation : "name" in W && W.name && (q = W));
|
|
337
|
+
let J = q?.target ?? o.actionDefinition.targetType;
|
|
338
|
+
if (!J) throw Error("No target type for create");
|
|
339
|
+
let Y = U?.ownerTransfer ?? G, X, Z = q?.behaviours?.includes(RelationBehaviourType.VALIDATE_CREATE);
|
|
340
|
+
if (L && Z && V) try {
|
|
341
|
+
await V.validateCreateRelation(q, Y, I);
|
|
342
|
+
} catch (o) {
|
|
343
|
+
if (isValidationError$1(o)) {
|
|
344
|
+
let F = o.toFieldErrors();
|
|
345
|
+
throw H && Object.keys(F).length > 0 && H.setErrors(F), o;
|
|
346
|
+
}
|
|
347
|
+
throw o;
|
|
348
|
+
}
|
|
349
|
+
else if (L && Z && z && q) {
|
|
350
|
+
let o = await z(I, q, Y);
|
|
351
|
+
if (o && Object.keys(o).length > 0) throw H?.setErrors(o), Error("Validation failed");
|
|
352
|
+
}
|
|
353
|
+
if (L) {
|
|
354
|
+
let o = `temp::${Date.now()}::${Math.random().toString(36).substring(2, 9)}`;
|
|
355
|
+
X = {
|
|
356
|
+
...I,
|
|
357
|
+
__tempId: o,
|
|
358
|
+
__isNew: !0
|
|
359
|
+
};
|
|
360
|
+
let L = U?.parentTransferId ?? K, R = U?.relationName;
|
|
361
|
+
if (L && F.data) {
|
|
362
|
+
let o = F.data.getSnapshot((o) => o.transfers.get(L)?.data);
|
|
363
|
+
if (R) {
|
|
364
|
+
let I = o?.[R];
|
|
365
|
+
Array.isArray(I) ? F.data.updateTransferFields(L, { [R]: [...I, X] }) : F.data.updateTransferFields(L, { [R]: X });
|
|
366
|
+
} else {
|
|
367
|
+
let I = [...o?.__items ?? [], X];
|
|
368
|
+
F.data.updateTransferFields(L, { __items: I });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
U?.onSubmitCreate && await U.onSubmitCreate(X);
|
|
372
|
+
} else if (R) X = await R(I, J);
|
|
373
|
+
else if (V && q) try {
|
|
374
|
+
X = (await V.createRelation(q, Y, I)).data;
|
|
375
|
+
} catch (o) {
|
|
376
|
+
if (isValidationError$1(o)) {
|
|
377
|
+
let F = o.toFieldErrors();
|
|
378
|
+
throw H && Object.keys(F).length > 0 && H.setErrors(F), o;
|
|
379
|
+
}
|
|
380
|
+
throw o;
|
|
381
|
+
}
|
|
382
|
+
else if (!R && !V) return;
|
|
383
|
+
else throw Error("Create requires relation context. Provide relation in createDialog or relationMetadata in additionalContext.");
|
|
384
|
+
F.closeDialog && F.closeDialog({
|
|
385
|
+
type: "created",
|
|
386
|
+
isEager: L ?? !1
|
|
387
|
+
});
|
|
388
|
+
let Q = o.actionDefinition.autoOpenAfterCreate !== !1, $ = o.targetPageDefinition;
|
|
389
|
+
Q && $ && F.navigation && !L && F.navigation.replacePage($, { transfer: X });
|
|
390
|
+
} catch (o) {
|
|
391
|
+
throw isValidationError$1(o) || F.data?.setTransferError(W, o), o;
|
|
392
|
+
} finally {
|
|
393
|
+
F.data?.setTransferLoading(W, !1);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
useCreateActionHandler.actionType = "CreateActionDefinition";
|
|
397
|
+
const useUpdateActionHandler = ((o) => async (F) => {
|
|
398
|
+
let I = F.transfer, L = I?.__identifier ?? I?.__signedIdentifier;
|
|
399
|
+
if (!L) throw Error("No transfer to update (missing identifier)");
|
|
400
|
+
let R = F.pageTransferId ?? L, z;
|
|
401
|
+
F.data && (z = F.data.getSnapshot((o) => o.transfers.get(R)?.data)), z ||= I, F.data?.setTransferLoading(R, !0);
|
|
402
|
+
try {
|
|
403
|
+
let { isEager: I } = F, L = F;
|
|
404
|
+
if (I) {
|
|
405
|
+
let { parentTransferId: o, relationName: I } = L;
|
|
406
|
+
if (o && I && F.data) {
|
|
407
|
+
let L = F.data.getSnapshot((F) => F.transfers.get(o)?.data);
|
|
408
|
+
if (L) {
|
|
409
|
+
let R = L[I];
|
|
410
|
+
if (Array.isArray(R)) {
|
|
411
|
+
let L = R.map((o) => {
|
|
412
|
+
let F = o.__tempId, I = z.__tempId;
|
|
413
|
+
return F && I && F === I || o.__identifier && o.__identifier === z.__identifier || o.__signedIdentifier && o.__signedIdentifier === z.__signedIdentifier ? { ...z } : o;
|
|
414
|
+
});
|
|
415
|
+
F.data.updateTransferFields(o, { [I]: L });
|
|
416
|
+
} else F.data.updateTransferFields(o, { [I]: { ...z } });
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
F.data?.setTransferData(R, z), F.navigation?.goBack();
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
let B = resolveTargetClassType(o);
|
|
423
|
+
if (!B) throw Error("No target type for update");
|
|
424
|
+
let { onUpdate: V, api: H } = F, U;
|
|
425
|
+
if (V) U = await V(z, B);
|
|
426
|
+
else if (H) U = (await H.update(B, z)).data, U = (await H.refresh(B, U)).data;
|
|
427
|
+
else return;
|
|
428
|
+
F.data?.setTransferData(R, U);
|
|
429
|
+
} catch (o) {
|
|
430
|
+
throw F.data?.setTransferError(R, o), o;
|
|
431
|
+
} finally {
|
|
432
|
+
F.data?.setTransferLoading(R, !1);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
useUpdateActionHandler.actionType = "UpdateActionDefinition";
|
|
436
|
+
const useDeleteActionHandler = ((o) => async (F) => {
|
|
437
|
+
let I = F.transfer, L = I?.__identifier ?? I?.__signedIdentifier;
|
|
438
|
+
if (!L) throw Error("No transfer to delete (missing identifier)");
|
|
439
|
+
F.data?.setTransferLoading(L, !0);
|
|
440
|
+
try {
|
|
441
|
+
let R = resolveTargetClassType(o);
|
|
442
|
+
if (!R) throw Error("No target type for delete");
|
|
443
|
+
let { onDelete: z, api: B } = F;
|
|
444
|
+
if (z) await z(L, R);
|
|
445
|
+
else if (B) await B.delete(R, I);
|
|
446
|
+
else return;
|
|
447
|
+
F.data?.clearTransfer(L), F.navigation?.goBack();
|
|
448
|
+
} catch (o) {
|
|
449
|
+
throw F.data?.setTransferError(L, o), o;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
useDeleteActionHandler.actionType = "DeleteActionDefinition";
|
|
453
|
+
const useBulkDeleteActionHandler = ((o) => async (F) => {
|
|
454
|
+
let I = F.selectedRows;
|
|
455
|
+
if (!I || I.length === 0) return;
|
|
456
|
+
let L = o.actionDefinition.targetType;
|
|
457
|
+
if (!L) throw Error("No target type for bulk delete");
|
|
458
|
+
let { onBulkDelete: R, api: z } = F, B = I.map((o) => o.__identifier ?? o.__signedIdentifier).filter(Boolean);
|
|
459
|
+
if (R) await R(B, L);
|
|
460
|
+
else if (z) {
|
|
461
|
+
let o = I.filter((o) => o.__signedIdentifier).map((o) => z.delete(L, o));
|
|
462
|
+
await Promise.all(o);
|
|
463
|
+
} else return;
|
|
464
|
+
for (let o of B) F.data?.clearTransfer(o);
|
|
465
|
+
});
|
|
466
|
+
useBulkDeleteActionHandler.actionType = "BulkDeleteActionDefinition";
|
|
467
|
+
const useRowDeleteActionHandler = ((o) => async (F) => {
|
|
468
|
+
let I = F.transfer, L = I?.__identifier ?? I?.__signedIdentifier, { isEager: R, parentTransferId: z, relationName: B } = F;
|
|
469
|
+
if (R && z && F.data) {
|
|
470
|
+
let o = F.data.getSnapshot((o) => o.transfers.get(z)?.data);
|
|
471
|
+
if (B) {
|
|
472
|
+
let R = o?.[B];
|
|
473
|
+
if (Array.isArray(R)) {
|
|
474
|
+
let o = R.filter((o) => (o.__identifier ?? o.__signedIdentifier ?? o.__tempId) !== (L ?? I?.__tempId));
|
|
475
|
+
F.data.updateTransferFields(z, { [B]: o });
|
|
476
|
+
} else F.data.updateTransferFields(z, { [B]: null });
|
|
477
|
+
} else {
|
|
478
|
+
let R = (o?.__items ?? []).filter((o) => (o.__identifier ?? o.__signedIdentifier ?? o.__tempId) !== (L ?? I?.__tempId));
|
|
479
|
+
F.data.updateTransferFields(z, { __items: R });
|
|
480
|
+
}
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if (!L) return;
|
|
484
|
+
let V = o.actionDefinition.targetType;
|
|
485
|
+
if (!V) throw Error("No target type for row delete");
|
|
486
|
+
let { onRowDelete: H, api: U } = F;
|
|
487
|
+
if (H) await H(L, V);
|
|
488
|
+
else if (U) await U.delete(V, I);
|
|
489
|
+
else return;
|
|
490
|
+
F.data?.clearTransfer(L);
|
|
491
|
+
});
|
|
492
|
+
useRowDeleteActionHandler.actionType = "RowDeleteActionDefinition";
|
|
493
|
+
const useGetTemplateActionHandler = ((o) => async (F) => {
|
|
494
|
+
let I = o.actionDefinition.targetType;
|
|
495
|
+
if (!I) throw Error("No target type for get template");
|
|
496
|
+
let { onGetTemplate: L, api: R } = F, z;
|
|
497
|
+
if (L) z = await L(I);
|
|
498
|
+
else if (R) z = (await R.getTemplate(I)).data;
|
|
499
|
+
else throw Error("API not available in context");
|
|
500
|
+
F.data?.setTransferData(F.pageTransferId ?? "new", z);
|
|
501
|
+
});
|
|
502
|
+
useGetTemplateActionHandler.actionType = "GetTemplateActionDefinition";
|
|
503
|
+
function getRelation$2(o, F) {
|
|
504
|
+
if (o.relation) return o.relation;
|
|
505
|
+
let I = F.ownerDataElement;
|
|
506
|
+
return I && I["@type"] === "RelationType" ? I : null;
|
|
507
|
+
}
|
|
508
|
+
const useSetActionHandler = ((o) => async (F) => {
|
|
509
|
+
let I = F, { ownerTransfer: L, selectedEntity: R, api: z, onSet: B } = I;
|
|
510
|
+
if (!L || !R) throw Error("Missing owner or selected transfer for set");
|
|
511
|
+
let V = L.__identifier ?? L.__signedIdentifier, H = R.__identifier ?? R.__signedIdentifier;
|
|
512
|
+
if (!V || !H) throw Error("Missing transfer identifiers for set");
|
|
513
|
+
let U = o.actionDefinition.name ?? "";
|
|
514
|
+
if (B) await B(V, U, H);
|
|
515
|
+
else if (z) {
|
|
516
|
+
let F = getRelation$2(I, o);
|
|
517
|
+
if (!F) throw Error("Cannot determine relation for set action");
|
|
518
|
+
await z.setRelation(F, L, R);
|
|
519
|
+
}
|
|
520
|
+
F.closeDialog?.({
|
|
521
|
+
type: "selected",
|
|
522
|
+
data: R
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
useSetActionHandler.actionType = "SetActionDefinition";
|
|
526
|
+
const useUnsetActionHandler = ((o) => async (F) => {
|
|
527
|
+
let I = F.transfer, L = I?.__identifier ?? I?.__signedIdentifier;
|
|
528
|
+
if (!L) return;
|
|
529
|
+
let R = o.actionDefinition.name ?? "", z = F, { onUnset: B, api: V } = z;
|
|
530
|
+
if (B) await B(L, R);
|
|
531
|
+
else if (V) {
|
|
532
|
+
let F = getRelation$2(z, o);
|
|
533
|
+
if (!F) throw Error("Cannot determine relation for unset action");
|
|
534
|
+
await V.unsetRelation(F, I);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
useUnsetActionHandler.actionType = "UnsetActionDefinition";
|
|
538
|
+
const useAddActionHandler = ((o) => async (F) => {
|
|
539
|
+
let I = F, { ownerTransfer: L, selectedEntities: R, api: z, onAdd: B } = I;
|
|
540
|
+
if (!L || !R?.length) throw Error("Missing transfers for add");
|
|
541
|
+
let V = L.__identifier ?? L.__signedIdentifier;
|
|
542
|
+
if (!V) throw Error("Missing owner transfer identifier for add");
|
|
543
|
+
let H = R.map((o) => o.__identifier ?? o.__signedIdentifier).filter(Boolean), U = o.actionDefinition.name ?? "";
|
|
544
|
+
if (B) await B(V, U, H);
|
|
545
|
+
else if (z) {
|
|
546
|
+
let F = getRelation$2(I, o);
|
|
547
|
+
if (!F) throw Error("Cannot determine relation for add action");
|
|
548
|
+
await z.addToRelation(F, L, R);
|
|
549
|
+
}
|
|
550
|
+
F.closeDialog?.({
|
|
551
|
+
type: "selected",
|
|
552
|
+
data: R
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
useAddActionHandler.actionType = "AddActionDefinition";
|
|
556
|
+
const useRemoveActionHandler = ((o) => async (F) => {
|
|
557
|
+
let I = F, L = F, R = F.transfer, z = R?.__identifier ?? R?.__signedIdentifier;
|
|
558
|
+
if (L.isEager && L.parentTransferId && F.data) {
|
|
559
|
+
let o = L.parentTransferId, I = L.relationName, B = F.data.getSnapshot((F) => F.transfers.get(o)?.data);
|
|
560
|
+
if (I) {
|
|
561
|
+
let L = (B?.[I] ?? []).filter((o) => (o.__identifier ?? o.__signedIdentifier ?? o.__tempId) !== (z ?? R?.__tempId));
|
|
562
|
+
F.data.updateTransferFields(o, { [I]: L });
|
|
563
|
+
} else {
|
|
564
|
+
let I = (B?.__items ?? []).filter((o) => (o.__identifier ?? o.__signedIdentifier ?? o.__tempId) !== (z ?? R?.__tempId));
|
|
565
|
+
F.data.updateTransferFields(o, { __items: I });
|
|
566
|
+
}
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
let { ownerTransfer: B, api: V, onRemove: H } = I, U = B?.__identifier ?? B?.__signedIdentifier;
|
|
570
|
+
if (!U || !z) return;
|
|
571
|
+
let W = o.actionDefinition.name ?? "";
|
|
572
|
+
if (H) await H(U, W, [z]);
|
|
573
|
+
else if (V) {
|
|
574
|
+
let F = getRelation$2(I, o);
|
|
575
|
+
if (!F) throw Error("Cannot determine relation for remove action");
|
|
576
|
+
await V.removeFromRelation(F, B, [R]);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
useRemoveActionHandler.actionType = "RemoveActionDefinition";
|
|
580
|
+
const useBulkRemoveActionHandler = ((o) => async (F) => {
|
|
581
|
+
let I = F, L = F, R = F.selectedRows;
|
|
582
|
+
if (!R?.length) return;
|
|
583
|
+
if (L.isEager && L.parentTransferId && F.data) {
|
|
584
|
+
let o = L.parentTransferId, I = L.relationName, z = new Set(R.map((o) => o.__identifier ?? o.__signedIdentifier ?? o.__tempId).filter(Boolean)), B = F.data.getSnapshot((F) => F.transfers.get(o)?.data);
|
|
585
|
+
if (I) {
|
|
586
|
+
let L = (B?.[I] ?? []).filter((o) => !z.has(o.__identifier ?? o.__signedIdentifier ?? o.__tempId));
|
|
587
|
+
F.data.updateTransferFields(o, { [I]: L });
|
|
588
|
+
} else {
|
|
589
|
+
let I = (B?.__items ?? []).filter((o) => !z.has(o.__identifier ?? o.__signedIdentifier ?? o.__tempId));
|
|
590
|
+
F.data.updateTransferFields(o, { __items: I });
|
|
591
|
+
}
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
let { ownerTransfer: z, api: B, onBulkRemove: V } = I, H = z?.__identifier ?? z?.__signedIdentifier;
|
|
595
|
+
if (!H) return;
|
|
596
|
+
let U = R.map((o) => o.__identifier ?? o.__signedIdentifier).filter(Boolean), W = o.actionDefinition.name ?? "";
|
|
597
|
+
if (V) await V(H, W, U);
|
|
598
|
+
else if (B) {
|
|
599
|
+
let F = getRelation$2(I, o);
|
|
600
|
+
if (!F) throw Error("Cannot determine relation for bulk remove action");
|
|
601
|
+
let L = R.filter((o) => o.__signedIdentifier);
|
|
602
|
+
await B.removeFromRelation(F, z, L);
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
useBulkRemoveActionHandler.actionType = "BulkRemoveActionDefinition";
|
|
606
|
+
const useClearActionHandler = ((o) => async (F) => {
|
|
607
|
+
let I = F.transfer, L = I?.__identifier ?? I?.__signedIdentifier;
|
|
608
|
+
if (!L) return;
|
|
609
|
+
let R = F, { api: z, onClear: B } = R, V = o.actionDefinition.name ?? "";
|
|
610
|
+
if (B) await B(L, V);
|
|
611
|
+
else if (z) {
|
|
612
|
+
let F = getRelation$2(R, o);
|
|
613
|
+
if (!F) throw Error("Cannot determine relation for clear action");
|
|
614
|
+
await z.unsetRelation(F, I);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
useClearActionHandler.actionType = "ClearActionDefinition";
|
|
618
|
+
const useRefreshRelationActionHandler = ((o) => async (F) => {
|
|
619
|
+
let I = F.transfer, L = I?.__identifier ?? I?.__signedIdentifier;
|
|
620
|
+
if (!L) return;
|
|
621
|
+
let R = F, { api: z, onRefreshRelation: B } = R, V = o.actionDefinition.name ?? "";
|
|
622
|
+
if (B) await B(L, V);
|
|
623
|
+
else if (z) {
|
|
624
|
+
let F = getRelation$2(R, o);
|
|
625
|
+
if (!F) throw Error("Cannot determine relation for refresh action");
|
|
626
|
+
F.isCollection === !1 ? await z.getRelation(F, I) : await z.listRelation(F, I);
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
useRefreshRelationActionHandler.actionType = "RefreshRelationActionDefinition";
|
|
630
|
+
const useFilterRelationActionHandler = ((o) => async (F) => {
|
|
631
|
+
let I = F;
|
|
632
|
+
I.onFilterRelation && I.onFilterRelation(o.actionDefinition.name ?? "");
|
|
633
|
+
});
|
|
634
|
+
useFilterRelationActionHandler.actionType = "FilterRelationActionDefinition";
|
|
635
|
+
function getRelation$1(o) {
|
|
636
|
+
return o.relation ?? null;
|
|
637
|
+
}
|
|
638
|
+
const useFilterActionHandler = ((o) => async (o) => {
|
|
639
|
+
o.onFilterRequest?.();
|
|
640
|
+
});
|
|
641
|
+
useFilterActionHandler.actionType = "FilterActionDefinition";
|
|
642
|
+
const useExportActionHandler = ((o) => async (F) => {
|
|
643
|
+
let I = o.actionDefinition.targetType;
|
|
644
|
+
if (!I) throw Error("No target type for export");
|
|
645
|
+
let L = F, { onExport: R, api: z } = L;
|
|
646
|
+
if (R) {
|
|
647
|
+
await R(I);
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
if (z) {
|
|
651
|
+
let o = getRelation$1(L);
|
|
652
|
+
if (!o) throw Error("Cannot determine relation for export action");
|
|
653
|
+
let R = (await z.exportRelation(o, F.transfer)).data, B = URL.createObjectURL(R), V = document.createElement("a");
|
|
654
|
+
V.href = B, V.download = `export_${I.simpleName ?? I.name}_${Date.now()}.csv`, V.click(), URL.revokeObjectURL(B);
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
useExportActionHandler.actionType = "ExportActionDefinition";
|
|
658
|
+
const useInlineCreateRowActionHandler = ((o) => async (o) => {
|
|
659
|
+
o.onInlineCreateRow?.();
|
|
660
|
+
});
|
|
661
|
+
useInlineCreateRowActionHandler.actionType = "InlineCreateRowActionDefinition";
|
|
662
|
+
function isValidationError(o) {
|
|
663
|
+
return typeof o == "object" && !!o && o.name === "ValidationError";
|
|
664
|
+
}
|
|
665
|
+
function hasStatus(o, ...F) {
|
|
666
|
+
if (typeof o == "object" && o) {
|
|
667
|
+
let I = o.status;
|
|
668
|
+
return I !== void 0 && F.includes(I);
|
|
669
|
+
}
|
|
670
|
+
return !1;
|
|
671
|
+
}
|
|
672
|
+
function handleOperationError(o, F, I, L) {
|
|
673
|
+
if (isValidationError(o)) {
|
|
674
|
+
let R = o.toFieldErrors();
|
|
675
|
+
L && Object.keys(R).length > 0 && L.setErrors(R), I?.error(`Validation failed for ${F}`);
|
|
676
|
+
} else if (hasStatus(o, 401, 403)) I?.error(`Access denied: You don't have permission to execute ${F}`);
|
|
677
|
+
else if (hasStatus(o, 404)) I?.error(`Resource not found for ${F}`);
|
|
678
|
+
else {
|
|
679
|
+
let L = o instanceof Error ? o.message : "Unknown error";
|
|
680
|
+
I?.error(`Operation ${F} failed: ${L}`);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
function openOperationOutputPage(o, F, I, L) {
|
|
684
|
+
let R = o.targetPageDefinition;
|
|
685
|
+
if (!F || !R) return;
|
|
686
|
+
let z = {
|
|
687
|
+
transfer: F,
|
|
688
|
+
isOperationOutput: !0,
|
|
689
|
+
isMappedOutput: (I.output?.behaviours ?? []).some((o) => [
|
|
690
|
+
"UPDATE",
|
|
691
|
+
"DELETE",
|
|
692
|
+
"REFRESH"
|
|
693
|
+
].includes(o))
|
|
694
|
+
};
|
|
695
|
+
String(R.openInDialog) === "true" ? L.navigation?.openDialog(R, z) : L.navigation?.navigateTo(R, z);
|
|
696
|
+
}
|
|
697
|
+
function triggerPageRefresh(o) {
|
|
698
|
+
let { refreshPage: F } = o;
|
|
699
|
+
F?.();
|
|
700
|
+
}
|
|
701
|
+
function toOperationInfo(o) {
|
|
702
|
+
return {
|
|
703
|
+
name: o.name,
|
|
704
|
+
isStatic: o.operationType === "STATIC",
|
|
705
|
+
isMapped: o.operationType === "MAPPED",
|
|
706
|
+
hasInput: !!o.input,
|
|
707
|
+
inputType: o.input?.target
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
const useCallOperationActionHandler = ((o) => async (F) => {
|
|
711
|
+
let I = o.actionDefinition, L = I.operation;
|
|
712
|
+
if (!L) throw Error("No operation defined for CallOperationAction");
|
|
713
|
+
let { onCallOperation: R, api: z } = F, { notifications: B, validation: V } = F, H = F.transfer;
|
|
714
|
+
try {
|
|
715
|
+
if (R) {
|
|
716
|
+
let I = await R(L, H, H);
|
|
717
|
+
B?.success(`${L.name} completed successfully`), openOperationOutputPage(o, I, L, F), triggerPageRefresh(F);
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
if (z) {
|
|
721
|
+
let R = I.targetType ?? L.eContainer;
|
|
722
|
+
if (!R) throw Error("No owner type for operation call");
|
|
723
|
+
let V = toOperationInfo(L), U = await z.invokeOperation(R, V, H, H);
|
|
724
|
+
B?.success(`${L.name} completed successfully`), openOperationOutputPage(o, U.data, L, F), triggerPageRefresh(F);
|
|
725
|
+
}
|
|
726
|
+
} catch (o) {
|
|
727
|
+
throw handleOperationError(o, L.name, B, V), o;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
useCallOperationActionHandler.actionType = "CallOperationActionDefinition";
|
|
731
|
+
const useBulkCallOperationActionHandler = ((o) => async (F) => {
|
|
732
|
+
let I = o.actionDefinition, L = I.operation;
|
|
733
|
+
if (!L) throw Error("No operation defined for BulkCallOperationAction");
|
|
734
|
+
let R = F.selectedRows;
|
|
735
|
+
if (!R || R.length === 0) return;
|
|
736
|
+
let { onBulkCallOperation: z, api: B } = F, { notifications: V, validation: H } = F;
|
|
737
|
+
try {
|
|
738
|
+
if (z) {
|
|
739
|
+
await z(L, R), V?.success(`${L.name} completed on ${R.length} item(s)`), triggerPageRefresh(F);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
if (B) {
|
|
743
|
+
let o = I.targetType ?? L.eContainer;
|
|
744
|
+
if (!o) throw Error("No owner type for bulk operation call");
|
|
745
|
+
let z = toOperationInfo(L), H = R.map((F) => B.invokeOperation(o, z, F, F));
|
|
746
|
+
await Promise.all(H), V?.success(`${L.name} completed on ${R.length} item(s)`), triggerPageRefresh(F);
|
|
747
|
+
}
|
|
748
|
+
} catch (o) {
|
|
749
|
+
throw handleOperationError(o, L.name, V, H), o;
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
useBulkCallOperationActionHandler.actionType = "BulkCallOperationActionDefinition";
|
|
753
|
+
const useInputFormCallOperationActionHandler = ((o) => async (F) => {
|
|
754
|
+
let I = o.actionDefinition, L = I.operation;
|
|
755
|
+
if (!L) throw Error("No operation defined for InputFormCallOperationAction");
|
|
756
|
+
let R = F, { onInputFormCallOperation: z, api: B, pageTransferId: V } = R, { notifications: H, validation: U } = F, W = F.transfer, G = R.inputData;
|
|
757
|
+
if (!G && F.data && V && (G = F.data.getSnapshot((o) => o.transfers.get(V)?.data)), G) try {
|
|
758
|
+
if (z) {
|
|
759
|
+
let I = await z(L, W, G);
|
|
760
|
+
F.closeDialog?.({ type: "submitted" }), H?.success(`${L.name} completed successfully`), openOperationOutputPage(o, I, L, F), triggerPageRefresh(F);
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (B) {
|
|
764
|
+
let R = I.targetType ?? L.eContainer;
|
|
765
|
+
if (!R) throw Error("No owner type for input form operation call");
|
|
766
|
+
let z = toOperationInfo(L), V = await B.invokeOperation(R, z, W, G);
|
|
767
|
+
F.closeDialog?.({ type: "submitted" }), H?.success(`${L.name} completed successfully`), openOperationOutputPage(o, V.data, L, F), triggerPageRefresh(F);
|
|
768
|
+
}
|
|
769
|
+
} catch (o) {
|
|
770
|
+
throw handleOperationError(o, L.name, H, U), o;
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
useInputFormCallOperationActionHandler.actionType = "InputFormCallOperationActionDefinition";
|
|
774
|
+
const useInputSelectorCallOperationActionHandler = ((o) => async (F) => {
|
|
775
|
+
let I = o.actionDefinition, L = I.operation;
|
|
776
|
+
if (!L) throw Error("No operation defined for InputSelectorCallOperationAction");
|
|
777
|
+
let { onInputSelectorCallOperation: R, api: z, selectedEntity: B, ownerTransfer: V } = F, { notifications: H, validation: U } = F, W = F.transfer ?? V;
|
|
778
|
+
if (B) try {
|
|
779
|
+
if (R) {
|
|
780
|
+
let I = await R(L, W, B);
|
|
781
|
+
F.closeDialog?.({ type: "submitted" }), H?.success(`${L.name} completed successfully`), openOperationOutputPage(o, I, L, F), triggerPageRefresh(F);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
if (z) {
|
|
785
|
+
let R = I.targetType ?? L.eContainer;
|
|
786
|
+
if (!R) throw Error("No owner type for input selector operation call");
|
|
787
|
+
let V = toOperationInfo(L), U = await z.invokeOperation(R, V, W, B);
|
|
788
|
+
F.closeDialog?.({ type: "submitted" }), H?.success(`${L.name} completed successfully`), openOperationOutputPage(o, U.data, L, F), triggerPageRefresh(F);
|
|
789
|
+
}
|
|
790
|
+
} catch (o) {
|
|
791
|
+
throw handleOperationError(o, L.name, H, U), o;
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
useInputSelectorCallOperationActionHandler.actionType = "InputSelectorCallOperationActionDefinition";
|
|
795
|
+
const useParameterlessCallOperationActionHandler = ((o) => async (F) => {
|
|
796
|
+
let I = o.actionDefinition, L = I.operation;
|
|
797
|
+
if (!L) throw Error("No operation defined for ParameterlessCallOperationAction");
|
|
798
|
+
let { onParameterlessCallOperation: R, api: z } = F, { notifications: B, validation: V } = F, H = F.transfer;
|
|
799
|
+
try {
|
|
800
|
+
if (R) {
|
|
801
|
+
let I = await R(L, H);
|
|
802
|
+
B?.success(`${L.name} completed successfully`), openOperationOutputPage(o, I, L, F), triggerPageRefresh(F);
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
if (z) {
|
|
806
|
+
let R = I.targetType ?? L.eContainer;
|
|
807
|
+
if (!R) throw Error("No owner type for parameterless operation call");
|
|
808
|
+
let V = toOperationInfo(L), U = await z.invokeOperation(R, V, H, void 0);
|
|
809
|
+
B?.success(`${L.name} completed successfully`), openOperationOutputPage(o, U.data, L, F), triggerPageRefresh(F);
|
|
810
|
+
}
|
|
811
|
+
} catch (o) {
|
|
812
|
+
throw handleOperationError(o, L.name, B, V), o;
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
useParameterlessCallOperationActionHandler.actionType = "ParameterlessCallOperationActionDefinition";
|
|
816
|
+
function getRelation(o, F) {
|
|
817
|
+
if (o.relation) return o.relation;
|
|
818
|
+
let I = F.ownerDataElement;
|
|
819
|
+
return I && I["@type"] === "RelationType" ? I : null;
|
|
820
|
+
}
|
|
821
|
+
const useAutocompleteRangeActionHandler = ((o) => async (F) => {
|
|
822
|
+
let I = o.actionDefinition.targetType;
|
|
823
|
+
if (!I) throw Error("No target type for autocomplete range");
|
|
824
|
+
let L = F, { onAutocompleteRange: R, api: z, onRangeResult: B } = L, V = L.searchText ?? "";
|
|
825
|
+
if (R) {
|
|
826
|
+
let o = await R(I, V);
|
|
827
|
+
B?.(o);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
if (z) {
|
|
831
|
+
let F = getRelation(L, o);
|
|
832
|
+
if (!F) throw Error("Cannot determine relation for autocomplete range");
|
|
833
|
+
let I = await z.getRelationRange(F, L.ownerTransfer, V ? { _filter: { contains: V } } : void 0);
|
|
834
|
+
B?.(I.data);
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
useAutocompleteRangeActionHandler.actionType = "AutocompleteRangeActionDefinition";
|
|
838
|
+
const useAutocompleteSetActionHandler = ((o) => async (F) => {
|
|
839
|
+
let I = F, { ownerTransfer: L, selectedEntity: R, api: z, onAutocompleteSet: B } = I, V = L?.__identifier ?? L?.__signedIdentifier, H = R?.__identifier ?? R?.__signedIdentifier;
|
|
840
|
+
if (!V || !H) return;
|
|
841
|
+
let U = o.actionDefinition.name ?? "";
|
|
842
|
+
if (B) {
|
|
843
|
+
await B(V, U, H);
|
|
844
|
+
return;
|
|
845
|
+
}
|
|
846
|
+
if (z) {
|
|
847
|
+
let F = getRelation(I, o);
|
|
848
|
+
if (!F) throw Error("Cannot determine relation for autocomplete set");
|
|
849
|
+
await z.setRelation(F, L, R);
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
useAutocompleteSetActionHandler.actionType = "AutocompleteSetActionDefinition";
|
|
853
|
+
const useAutocompleteAddActionHandler = ((o) => async (F) => {
|
|
854
|
+
let I = F, { ownerTransfer: L, selectedEntities: R, api: z, onAutocompleteAdd: B } = I, V = L?.__identifier ?? L?.__signedIdentifier;
|
|
855
|
+
if (!V || !R?.length) return;
|
|
856
|
+
let H = R.map((o) => o.__identifier ?? o.__signedIdentifier).filter(Boolean), U = o.actionDefinition.name ?? "";
|
|
857
|
+
if (B) {
|
|
858
|
+
await B(V, U, H);
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if (z) {
|
|
862
|
+
let F = getRelation(I, o);
|
|
863
|
+
if (!F) throw Error("Cannot determine relation for autocomplete add");
|
|
864
|
+
let B = R.filter((o) => o.__signedIdentifier);
|
|
865
|
+
await z.addToRelation(F, L, B);
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
useAutocompleteAddActionHandler.actionType = "AutocompleteAddActionDefinition";
|
|
869
|
+
const usePreFetchActionHandler = ((o) => async (F) => {
|
|
870
|
+
let I = o.actionDefinition.targetType;
|
|
871
|
+
if (!I) throw Error("No target type for pre-fetch");
|
|
872
|
+
let L = F;
|
|
873
|
+
if (L.onPreFetch) {
|
|
874
|
+
let o = await L.onPreFetch(I, F.transfer?.__identifier);
|
|
875
|
+
o.__identifier && F.data.setTransferData(o.__identifier, o);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
usePreFetchActionHandler.actionType = "PreFetchActionDefinition";
|
|
879
|
+
const useCustomActionHandler = ((o) => async (F) => {
|
|
880
|
+
let I = F;
|
|
881
|
+
I.onCustomAction && await I.onCustomAction(o, F);
|
|
882
|
+
});
|
|
883
|
+
useCustomActionHandler.actionType = "CustomActionDefinition";
|
|
884
|
+
var ApiContext = createContext(null);
|
|
885
|
+
function useApi() {
|
|
886
|
+
let o = useContext(ApiContext);
|
|
887
|
+
if (!o) throw Error("useApi must be used within ApiProvider");
|
|
888
|
+
return o.api;
|
|
889
|
+
}
|
|
890
|
+
function ApiProvider({ children: o, api: F }) {
|
|
891
|
+
return /* @__PURE__ */ jsx(ApiContext.Provider, {
|
|
892
|
+
value: { api: F },
|
|
893
|
+
children: o
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
async function executeWithLifecycle(o, F, I, L) {
|
|
897
|
+
let R = () => o(I), z = {
|
|
898
|
+
...I,
|
|
899
|
+
action: L,
|
|
900
|
+
actionDefinition: L.actionDefinition,
|
|
901
|
+
page: I.page,
|
|
902
|
+
callDefault: R
|
|
903
|
+
};
|
|
904
|
+
if (!(F.before && await F.before(z) === !1)) try {
|
|
905
|
+
let L;
|
|
906
|
+
return L = F.execute ? await F.execute(z) : await o(I), F.after && await F.after(z, L), L;
|
|
907
|
+
} catch (o) {
|
|
908
|
+
if (F.onError && await F.onError(z, o) === !0) return;
|
|
909
|
+
throw o;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
var BUILTIN_HANDLERS = new Map([
|
|
913
|
+
["BackActionDefinition", useBackActionHandler],
|
|
914
|
+
["OpenPageActionDefinition", useOpenPageActionHandler],
|
|
915
|
+
["RowOpenPageActionDefinition", useRowOpenPageActionHandler],
|
|
916
|
+
["CancelActionDefinition", useCancelActionHandler],
|
|
917
|
+
["OpenFormActionDefinition", useOpenFormActionHandler],
|
|
918
|
+
["OpenCreateFormActionDefinition", useOpenCreateFormActionHandler],
|
|
919
|
+
["OpenOperationInputFormActionDefinition", useOpenOperationInputFormActionHandler],
|
|
920
|
+
["OpenSelectorActionDefinition", useOpenSelectorActionHandler],
|
|
921
|
+
["OpenAddSelectorActionDefinition", useOpenAddSelectorActionHandler],
|
|
922
|
+
["OpenSetSelectorActionDefinition", useOpenSetSelectorActionHandler],
|
|
923
|
+
["OpenOperationInputSelectorActionDefinition", useOpenOperationInputSelectorActionHandler],
|
|
924
|
+
["SelectorRangeActionDefinition", useSelectorRangeActionHandler],
|
|
925
|
+
["RefreshActionDefinition", useRefreshActionHandler],
|
|
926
|
+
["CreateActionDefinition", useCreateActionHandler],
|
|
927
|
+
["UpdateActionDefinition", useUpdateActionHandler],
|
|
928
|
+
["DeleteActionDefinition", useDeleteActionHandler],
|
|
929
|
+
["BulkDeleteActionDefinition", useBulkDeleteActionHandler],
|
|
930
|
+
["RowDeleteActionDefinition", useRowDeleteActionHandler],
|
|
931
|
+
["GetTemplateActionDefinition", useGetTemplateActionHandler],
|
|
932
|
+
["SetActionDefinition", useSetActionHandler],
|
|
933
|
+
["UnsetActionDefinition", useUnsetActionHandler],
|
|
934
|
+
["AddActionDefinition", useAddActionHandler],
|
|
935
|
+
["RemoveActionDefinition", useRemoveActionHandler],
|
|
936
|
+
["BulkRemoveActionDefinition", useBulkRemoveActionHandler],
|
|
937
|
+
["ClearActionDefinition", useClearActionHandler],
|
|
938
|
+
["RefreshRelationActionDefinition", useRefreshRelationActionHandler],
|
|
939
|
+
["FilterRelationActionDefinition", useFilterRelationActionHandler],
|
|
940
|
+
["FilterActionDefinition", useFilterActionHandler],
|
|
941
|
+
["ExportActionDefinition", useExportActionHandler],
|
|
942
|
+
["InlineCreateRowActionDefinition", useInlineCreateRowActionHandler],
|
|
943
|
+
["BulkCallOperationActionDefinition", useBulkCallOperationActionHandler],
|
|
944
|
+
["CallOperationActionDefinition", useCallOperationActionHandler],
|
|
945
|
+
["InputFormCallOperationActionDefinition", useInputFormCallOperationActionHandler],
|
|
946
|
+
["InputSelectorCallOperationActionDefinition", useInputSelectorCallOperationActionHandler],
|
|
947
|
+
["ParameterlessCallOperationActionDefinition", useParameterlessCallOperationActionHandler],
|
|
948
|
+
["AutocompleteAddActionDefinition", useAutocompleteAddActionHandler],
|
|
949
|
+
["AutocompleteRangeActionDefinition", useAutocompleteRangeActionHandler],
|
|
950
|
+
["AutocompleteSetActionDefinition", useAutocompleteSetActionHandler],
|
|
951
|
+
["PreFetchActionDefinition", usePreFetchActionHandler],
|
|
952
|
+
["CustomActionDefinition", useCustomActionHandler]
|
|
953
|
+
]);
|
|
954
|
+
function getActionHandler(o) {
|
|
955
|
+
return BUILTIN_HANDLERS.get(o.actionDefinition["@type"]);
|
|
956
|
+
}
|
|
957
|
+
function hasActionHandler$1(o) {
|
|
958
|
+
return getActionHandler(o) !== void 0;
|
|
959
|
+
}
|
|
960
|
+
function useActionDispatcher(o) {
|
|
961
|
+
let { navigation: F, data: L, registry: z, api: B, transfer: V, selectedRows: H, closeDialog: U, notifications: W, additionalContext: G, actionOverrides: K } = o, q = useMemo(() => ({
|
|
962
|
+
navigation: F,
|
|
963
|
+
data: L,
|
|
964
|
+
registry: z,
|
|
965
|
+
api: B,
|
|
966
|
+
transfer: V,
|
|
967
|
+
selectedRows: H,
|
|
968
|
+
closeDialog: U,
|
|
969
|
+
notifications: W,
|
|
970
|
+
...G
|
|
971
|
+
}), [
|
|
972
|
+
F,
|
|
973
|
+
L,
|
|
974
|
+
z,
|
|
975
|
+
B,
|
|
976
|
+
V,
|
|
977
|
+
H,
|
|
978
|
+
U,
|
|
979
|
+
W,
|
|
980
|
+
G
|
|
981
|
+
]), J = useCallback((o) => hasActionHandler$1(o), []);
|
|
982
|
+
return {
|
|
983
|
+
dispatch: useCallback(async (o, F) => {
|
|
984
|
+
let I = getActionHandler(o);
|
|
985
|
+
if (!I) {
|
|
986
|
+
let F = o.actionDefinition["@type"];
|
|
987
|
+
throw Error(`No handler for action type: ${F}`);
|
|
988
|
+
}
|
|
989
|
+
let L = I(o), R = F ? {
|
|
990
|
+
...q,
|
|
991
|
+
...F
|
|
992
|
+
} : q, z = o["xmi:id"], B = z ? K?.[z] : void 0;
|
|
993
|
+
B && Object.keys(B).length > 0 ? await executeWithLifecycle(L, B, R, o) : await L(R);
|
|
994
|
+
}, [q, K]),
|
|
995
|
+
canHandle: J
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
function useActionHandler(o) {
|
|
999
|
+
return useMemo(() => {
|
|
1000
|
+
let F = getActionHandler(o);
|
|
1001
|
+
if (!F) {
|
|
1002
|
+
let F = o.actionDefinition["@type"];
|
|
1003
|
+
throw Error(`No handler for action type: ${F}`);
|
|
1004
|
+
}
|
|
1005
|
+
return F(o);
|
|
1006
|
+
}, [o]);
|
|
1007
|
+
}
|
|
1008
|
+
function hasActionHandler(o) {
|
|
1009
|
+
return hasActionHandler$1(o);
|
|
1010
|
+
}
|
|
1011
|
+
const HEADER_SIGNED_IDENTIFIER = "X-Judo-SignedIdentifier", HEADER_MASK = "X-Judo-Mask", HEADER_MARK_SELECTED_RANGE_ITEMS = "X-Judo-Mark-Selected-Range-Items", HEADER_COUNT_RECORDS = "X-Judo-CountRecords", HEADER_TOKEN = "X-Token", DEFAULT_COMMAND_MASK = "{}", SUFFIX_TEMPLATE = "/~template", SUFFIX_GET = "/~get", SUFFIX_UPDATE = "/~update", SUFFIX_VALIDATE = "/~validate", SUFFIX_DELETE = "/~delete", SUFFIX_LIST = "/~list", SUFFIX_RANGE = "/~range", SUFFIX_CREATE = "/~create", SUFFIX_SET = "/~set", SUFFIX_UNSET = "/~unset", SUFFIX_ADD = "/~add", SUFFIX_REMOVE = "/~remove", SUFFIX_EXPORT = "/~export";
|
|
1012
|
+
var SPLITTER = "::", TRANSFER_SKIP_SEGMENT = "_default_transferobjecttypes";
|
|
1013
|
+
function restPath(o, F, I, L) {
|
|
1014
|
+
let R = `${F}${I ? I.split(SPLITTER).join("/") : ""}${L ?? ""}`;
|
|
1015
|
+
return `/${o.packageNameTokens?.length ? `${o.packageNameTokens.join("/")}/` : ""}${(o.simpleName ?? "").split(SPLITTER).filter((o) => !o.includes(TRANSFER_SKIP_SEGMENT)).join("/")}${R}`;
|
|
1016
|
+
}
|
|
1017
|
+
function getPathForApp(o, F) {
|
|
1018
|
+
if (!o) throw Error("Application context is required for path building. Ensure the API is properly initialized with an Application.");
|
|
1019
|
+
let I = F || "";
|
|
1020
|
+
return `/${o.modelName}${I.length && !I.startsWith("/") ? `/${I}` : I}`;
|
|
1021
|
+
}
|
|
1022
|
+
function rootPathForApp(o) {
|
|
1023
|
+
if (!o?.actor) throw Error("Application.actor is required for path building. Ensure the Application has a valid actor ClassType.");
|
|
1024
|
+
return `${o.actor.packageNameTokens?.length ? `${o.actor.packageNameTokens.join("/")}/` : ""}${o.actor.simpleName ?? o.actor.name ?? "Actor"}`;
|
|
1025
|
+
}
|
|
1026
|
+
function getPathForActor(o, F = "") {
|
|
1027
|
+
return getPathForApp(o, rootPathForApp(o) + (F.length && !F.startsWith("/") ? `/${F}` : F));
|
|
1028
|
+
}
|
|
1029
|
+
function getRelationPath(o, F, I = "/~list") {
|
|
1030
|
+
return getPathForActor(F, restPath(o?.eContainer, "/", o.name, I));
|
|
1031
|
+
}
|
|
1032
|
+
function getClassPath(o, F, I = "") {
|
|
1033
|
+
return getPathForActor(F, restPath(o, "", "", I));
|
|
1034
|
+
}
|
|
1035
|
+
function getMutationRelationPath(o, F, I, L = !1) {
|
|
1036
|
+
let R = o?.eContainer;
|
|
1037
|
+
return L ? getPathForActor(F, restPath(R, "/", o.name, I)) : getPathForActor(F, restPath(R, "/~update/", o.name, I));
|
|
1038
|
+
}
|
|
1039
|
+
function getOperationPath(o, F, I, L = "") {
|
|
1040
|
+
return getPathForActor(I, restPath(o, "/", F, L));
|
|
1041
|
+
}
|
|
1042
|
+
var JudoRestApi = class {
|
|
1043
|
+
config;
|
|
1044
|
+
fetchImpl;
|
|
1045
|
+
_defaultHeaders;
|
|
1046
|
+
constructor(o) {
|
|
1047
|
+
if (!o.application) throw Error("JudoRestApi requires 'application' in config. Ensure the API is created with a valid Application context.");
|
|
1048
|
+
if (!o.application.actor) throw Error("JudoRestApi requires 'application.actor' in config. Ensure the Application has a valid actor ClassType.");
|
|
1049
|
+
this.config = o, this.fetchImpl = o.fetch ?? globalThis.fetch.bind(globalThis), this._defaultHeaders = { ...o.defaultHeaders };
|
|
1050
|
+
}
|
|
1051
|
+
setDefaultHeaders(o) {
|
|
1052
|
+
this._defaultHeaders = o;
|
|
1053
|
+
}
|
|
1054
|
+
getUrl(o) {
|
|
1055
|
+
return `${this.config.baseUrl}${o}`;
|
|
1056
|
+
}
|
|
1057
|
+
serializeTransfer(o) {
|
|
1058
|
+
return this.config.transferSerializer ? this.config.transferSerializer.serialize(o) : o;
|
|
1059
|
+
}
|
|
1060
|
+
deserializeTransfer(o) {
|
|
1061
|
+
return this.config.transferDeserializer ? this.config.transferDeserializer.deserialize(o) : o;
|
|
1062
|
+
}
|
|
1063
|
+
deserializeArray(o) {
|
|
1064
|
+
return Array.isArray(o) ? this.config.transferDeserializer ? o.map((o) => this.config.transferDeserializer.deserialize(o)) : o : [];
|
|
1065
|
+
}
|
|
1066
|
+
async request(o, F, I = {}) {
|
|
1067
|
+
let L = this.getUrl(F), R = {
|
|
1068
|
+
method: o,
|
|
1069
|
+
headers: {
|
|
1070
|
+
"Content-Type": "application/json",
|
|
1071
|
+
...this._defaultHeaders,
|
|
1072
|
+
...I.headers
|
|
1073
|
+
},
|
|
1074
|
+
body: I.body === void 0 ? void 0 : JSON.stringify(I.body)
|
|
1075
|
+
};
|
|
1076
|
+
this.config.onRequest && (R = await this.config.onRequest(R));
|
|
1077
|
+
try {
|
|
1078
|
+
let o = await this.fetchImpl(L, R);
|
|
1079
|
+
if (this.config.onResponse && (o = await this.config.onResponse(o)), !o.ok) {
|
|
1080
|
+
let F = await o.text();
|
|
1081
|
+
if (o.status === 400 && F.length > 0) try {
|
|
1082
|
+
let o = JSON.parse(F);
|
|
1083
|
+
if (Array.isArray(o)) {
|
|
1084
|
+
let { ValidationError: F } = await import("./types-CbA9-fcJ.js");
|
|
1085
|
+
throw new F(o);
|
|
1086
|
+
}
|
|
1087
|
+
} catch (o) {
|
|
1088
|
+
if (o instanceof Error && o.name === "ValidationError") throw o;
|
|
1089
|
+
}
|
|
1090
|
+
throw Error(`HTTP ${o.status}: ${F}`);
|
|
1091
|
+
}
|
|
1092
|
+
let F;
|
|
1093
|
+
if (I.responseType === "blob") F = await o.blob();
|
|
1094
|
+
else {
|
|
1095
|
+
let I = await o.text();
|
|
1096
|
+
F = I.length > 0 ? JSON.parse(I) : void 0;
|
|
1097
|
+
}
|
|
1098
|
+
return {
|
|
1099
|
+
data: F,
|
|
1100
|
+
status: o.status,
|
|
1101
|
+
headers: o.headers
|
|
1102
|
+
};
|
|
1103
|
+
} catch (o) {
|
|
1104
|
+
throw this.config.onError && this.config.onError(o), o;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
async getTemplate(o) {
|
|
1108
|
+
let F = getClassPath(o, this.config.application, SUFFIX_TEMPLATE), I = await this.request("GET", F);
|
|
1109
|
+
return {
|
|
1110
|
+
...I,
|
|
1111
|
+
data: this.deserializeTransfer(I.data)
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
async refresh(o, F, I) {
|
|
1115
|
+
let L = getClassPath(o, this.config.application, SUFFIX_GET), R = await this.request("POST", L, {
|
|
1116
|
+
body: I ?? {},
|
|
1117
|
+
headers: { [HEADER_SIGNED_IDENTIFIER]: F.__signedIdentifier }
|
|
1118
|
+
});
|
|
1119
|
+
return {
|
|
1120
|
+
...R,
|
|
1121
|
+
data: this.deserializeTransfer(R.data)
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
async update(o, F, I) {
|
|
1125
|
+
let L = getClassPath(o, this.config.application, SUFFIX_UPDATE), R = await this.request("POST", L, {
|
|
1126
|
+
body: this.serializeTransfer(F),
|
|
1127
|
+
headers: {
|
|
1128
|
+
[HEADER_SIGNED_IDENTIFIER]: F.__signedIdentifier,
|
|
1129
|
+
[HEADER_MASK]: I ?? "{}"
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
return {
|
|
1133
|
+
...R,
|
|
1134
|
+
data: this.deserializeTransfer(R.data)
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
async validateUpdate(o, F) {
|
|
1138
|
+
let I = getClassPath(o, this.config.application, SUFFIX_VALIDATE), L = await this.request("POST", I, {
|
|
1139
|
+
body: this.serializeTransfer(F),
|
|
1140
|
+
headers: { [HEADER_SIGNED_IDENTIFIER]: F.__signedIdentifier }
|
|
1141
|
+
});
|
|
1142
|
+
return {
|
|
1143
|
+
...L,
|
|
1144
|
+
data: this.deserializeTransfer(L.data)
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
async delete(o, F) {
|
|
1148
|
+
let I = getClassPath(o, this.config.application, SUFFIX_DELETE);
|
|
1149
|
+
return this.request("POST", I, { headers: { [HEADER_SIGNED_IDENTIFIER]: F.__signedIdentifier } });
|
|
1150
|
+
}
|
|
1151
|
+
async listRelation(o, F, I, L) {
|
|
1152
|
+
let R = getRelationPath(o, this.config.application, SUFFIX_LIST), z = {};
|
|
1153
|
+
F?.__signedIdentifier && (z[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier), L && (z[HEADER_COUNT_RECORDS] = "true");
|
|
1154
|
+
let B = await this.request("POST", R, {
|
|
1155
|
+
body: I ?? {},
|
|
1156
|
+
headers: z
|
|
1157
|
+
});
|
|
1158
|
+
return {
|
|
1159
|
+
...B,
|
|
1160
|
+
data: this.deserializeArray(B.data)
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
async getRelation(o, F, I) {
|
|
1164
|
+
let L = getRelationPath(o, this.config.application, SUFFIX_GET), R = await this.request("POST", L, {
|
|
1165
|
+
body: I ?? {},
|
|
1166
|
+
headers: { [HEADER_SIGNED_IDENTIFIER]: F.__signedIdentifier }
|
|
1167
|
+
}), z = R.data === void 0 || R.data === null ? null : this.deserializeTransfer(R.data);
|
|
1168
|
+
return {
|
|
1169
|
+
...R,
|
|
1170
|
+
data: z
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
async refreshAccessRelation(o, F) {
|
|
1174
|
+
let I = getRelationPath(o, this.config.application, SUFFIX_GET), L = await this.request("POST", I, { body: F ?? {} });
|
|
1175
|
+
return {
|
|
1176
|
+
...L,
|
|
1177
|
+
data: this.deserializeTransfer(L.data)
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
async getRelationRange(o, F, I, L) {
|
|
1181
|
+
let R = getRelationPath(o, this.config.application, SUFFIX_RANGE), z = {
|
|
1182
|
+
owner: F ?? {},
|
|
1183
|
+
queryCustomizer: I ?? {}
|
|
1184
|
+
}, B = { [HEADER_MARK_SELECTED_RANGE_ITEMS]: "true" };
|
|
1185
|
+
L && (B[HEADER_COUNT_RECORDS] = "true");
|
|
1186
|
+
let V = await this.request("POST", R, {
|
|
1187
|
+
body: z,
|
|
1188
|
+
headers: B
|
|
1189
|
+
});
|
|
1190
|
+
return {
|
|
1191
|
+
...V,
|
|
1192
|
+
data: this.deserializeArray(V.data)
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
async getRelationTemplate(o) {
|
|
1196
|
+
let F = getClassPath(o.target, this.config.application, SUFFIX_TEMPLATE), I = await this.request("GET", F);
|
|
1197
|
+
return {
|
|
1198
|
+
...I,
|
|
1199
|
+
data: this.deserializeTransfer(I.data)
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
async createRelation(o, F, I, L) {
|
|
1203
|
+
let R = o.isAccess, z = R ? getRelationPath(o, this.config.application, SUFFIX_CREATE) : getMutationRelationPath(o, this.config.application, SUFFIX_CREATE), B = { [HEADER_MASK]: L ?? "{}" };
|
|
1204
|
+
!R && F?.__signedIdentifier && (B[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier);
|
|
1205
|
+
let V = await this.request("POST", z, {
|
|
1206
|
+
body: this.serializeTransfer(I),
|
|
1207
|
+
headers: B
|
|
1208
|
+
});
|
|
1209
|
+
return {
|
|
1210
|
+
...V,
|
|
1211
|
+
data: this.deserializeTransfer(V.data)
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
async validateCreateRelation(o, F, I) {
|
|
1215
|
+
let L = o.isAccess, R = L ? getRelationPath(o, this.config.application, SUFFIX_VALIDATE) : getMutationRelationPath(o, this.config.application, SUFFIX_VALIDATE), z = {};
|
|
1216
|
+
!L && F?.__signedIdentifier && (z[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier);
|
|
1217
|
+
let B = await this.request("POST", R, {
|
|
1218
|
+
body: this.serializeTransfer(I),
|
|
1219
|
+
headers: z
|
|
1220
|
+
});
|
|
1221
|
+
return {
|
|
1222
|
+
...B,
|
|
1223
|
+
data: this.deserializeTransfer(B.data)
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
async setRelation(o, F, I) {
|
|
1227
|
+
let L = o.isAccess, R = getMutationRelationPath(o, this.config.application, SUFFIX_SET, L), z = {};
|
|
1228
|
+
L || (z[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier);
|
|
1229
|
+
let B = Array.isArray(I) ? I.map((o) => this.serializeTransfer(o)) : this.serializeTransfer(I);
|
|
1230
|
+
return this.request("POST", R, {
|
|
1231
|
+
body: B,
|
|
1232
|
+
headers: z
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
async unsetRelation(o, F) {
|
|
1236
|
+
let I = o.isAccess, L = getMutationRelationPath(o, this.config.application, SUFFIX_UNSET, I), R = {};
|
|
1237
|
+
return I || (R[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier), this.request("POST", L, { headers: R });
|
|
1238
|
+
}
|
|
1239
|
+
async addToRelation(o, F, I) {
|
|
1240
|
+
let L = o.isAccess, R = getMutationRelationPath(o, this.config.application, SUFFIX_ADD, L), z = {};
|
|
1241
|
+
return L || (z[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier), this.request("POST", R, {
|
|
1242
|
+
body: I.map((o) => this.serializeTransfer(o)),
|
|
1243
|
+
headers: z
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
async removeFromRelation(o, F, I) {
|
|
1247
|
+
let L = o.isAccess, R = getMutationRelationPath(o, this.config.application, SUFFIX_REMOVE, L), z = {};
|
|
1248
|
+
return L || (z[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier), this.request("POST", R, {
|
|
1249
|
+
body: I.map((o) => this.serializeTransfer(o)),
|
|
1250
|
+
headers: z
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
async exportRelation(o, F, I) {
|
|
1254
|
+
let L = getRelationPath(o, this.config.application, SUFFIX_EXPORT), R = {};
|
|
1255
|
+
return F?.__signedIdentifier && (R[HEADER_SIGNED_IDENTIFIER] = F.__signedIdentifier), this.request("POST", L, {
|
|
1256
|
+
body: I ?? {},
|
|
1257
|
+
headers: R,
|
|
1258
|
+
responseType: "blob"
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
async invokeOperation(o, F, I, L) {
|
|
1262
|
+
let R = getOperationPath(o, F.name, this.config.application), z = {};
|
|
1263
|
+
F.isMapped && !F.isStatic && I?.__signedIdentifier && (z[HEADER_SIGNED_IDENTIFIER] = I.__signedIdentifier);
|
|
1264
|
+
let B = await this.request("POST", R, {
|
|
1265
|
+
body: F.hasInput ? this.serializeTransfer(L) : void 0,
|
|
1266
|
+
headers: z
|
|
1267
|
+
});
|
|
1268
|
+
return B.data !== void 0 && B.data !== null ? {
|
|
1269
|
+
...B,
|
|
1270
|
+
data: this.deserializeTransfer(B.data)
|
|
1271
|
+
} : B;
|
|
1272
|
+
}
|
|
1273
|
+
async validateOperationInput(o, F, I, L) {
|
|
1274
|
+
let R = getOperationPath(o, F.name, this.config.application, SUFFIX_VALIDATE), z = {};
|
|
1275
|
+
F.isMapped && !F.isStatic && I?.__signedIdentifier && (z[HEADER_SIGNED_IDENTIFIER] = I.__signedIdentifier);
|
|
1276
|
+
let B = await this.request("POST", R, {
|
|
1277
|
+
body: this.serializeTransfer(L),
|
|
1278
|
+
headers: z
|
|
1279
|
+
});
|
|
1280
|
+
return {
|
|
1281
|
+
...B,
|
|
1282
|
+
data: this.deserializeTransfer(B.data)
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
async getOperationInputTemplate(o) {
|
|
1286
|
+
if (!o.inputType) throw Error(`Operation ${o.name} has no input type`);
|
|
1287
|
+
let F = getClassPath(o.inputType, this.config.application, SUFFIX_TEMPLATE), I = await this.request("GET", F);
|
|
1288
|
+
return {
|
|
1289
|
+
...I,
|
|
1290
|
+
data: this.deserializeTransfer(I.data)
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
async getOperationInputRange(o, F, I, L, R) {
|
|
1294
|
+
let z = getOperationPath(o, F.name, this.config.application, SUFFIX_RANGE), B = {
|
|
1295
|
+
owner: I ?? {},
|
|
1296
|
+
queryCustomizer: L ?? {}
|
|
1297
|
+
}, V = { [HEADER_MARK_SELECTED_RANGE_ITEMS]: "true" };
|
|
1298
|
+
R && (V[HEADER_COUNT_RECORDS] = "true");
|
|
1299
|
+
let H = await this.request("POST", z, {
|
|
1300
|
+
body: B,
|
|
1301
|
+
headers: V
|
|
1302
|
+
});
|
|
1303
|
+
return {
|
|
1304
|
+
...H,
|
|
1305
|
+
data: this.deserializeArray(H.data)
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
async getPrincipal() {
|
|
1309
|
+
let o = getPathForActor(this.config.application, "/~principal"), F = await this.request("GET", o);
|
|
1310
|
+
return {
|
|
1311
|
+
...F,
|
|
1312
|
+
data: this.deserializeTransfer(F.data)
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
async getMetadata() {
|
|
1316
|
+
let o = getPathForActor(this.config.application, "/~meta");
|
|
1317
|
+
return this.request("GET", o);
|
|
1318
|
+
}
|
|
1319
|
+
async uploadFile(o, F) {
|
|
1320
|
+
let I = (await this.request("POST", `${o}/~upload-token`)).data.token, L = new FormData();
|
|
1321
|
+
L.append("file", F);
|
|
1322
|
+
let R = `${this.config.baseUrl}/upload`, z = await this.fetchImpl(R, {
|
|
1323
|
+
method: "POST",
|
|
1324
|
+
headers: {
|
|
1325
|
+
...this._defaultHeaders,
|
|
1326
|
+
[HEADER_TOKEN]: I
|
|
1327
|
+
},
|
|
1328
|
+
body: L
|
|
1329
|
+
});
|
|
1330
|
+
if (!z.ok) throw Error(`Upload failed: HTTP ${z.status}`);
|
|
1331
|
+
return {
|
|
1332
|
+
data: await z.json(),
|
|
1333
|
+
status: z.status,
|
|
1334
|
+
headers: z.headers
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
async downloadFile(o, F = "attachment") {
|
|
1338
|
+
let I = `${this.config.baseUrl}/download?disposition=${F}`, L = await this.fetchImpl(I, {
|
|
1339
|
+
method: "GET",
|
|
1340
|
+
headers: {
|
|
1341
|
+
...this._defaultHeaders,
|
|
1342
|
+
[HEADER_TOKEN]: o
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
if (!L.ok) throw Error(`Download failed: HTTP ${L.status}`);
|
|
1346
|
+
return {
|
|
1347
|
+
data: await L.blob(),
|
|
1348
|
+
status: L.status,
|
|
1349
|
+
headers: L.headers
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
async findInstance(o, F, I) {
|
|
1353
|
+
let L = getRelationPath(o, this.config.application, SUFFIX_LIST), R = {
|
|
1354
|
+
_identifier: F,
|
|
1355
|
+
_seek: { limit: 1 }
|
|
1356
|
+
};
|
|
1357
|
+
I && (R._mask = I);
|
|
1358
|
+
let z = await this.request("POST", L, { body: R }), B = this.deserializeArray(z.data), V = B.length > 0 ? B[0] : null;
|
|
1359
|
+
return {
|
|
1360
|
+
...z,
|
|
1361
|
+
data: V
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
function createJudoRestApi(o) {
|
|
1366
|
+
return new JudoRestApi(o);
|
|
1367
|
+
}
|
|
1368
|
+
const BACKEND_PROPERTIES = new Set([
|
|
1369
|
+
"__identifier",
|
|
1370
|
+
"__entityType",
|
|
1371
|
+
"__deleteable",
|
|
1372
|
+
"__updateable",
|
|
1373
|
+
"__version"
|
|
1374
|
+
]), FRONTEND_PROPERTIES = new Set([
|
|
1375
|
+
"__isNew",
|
|
1376
|
+
"__items",
|
|
1377
|
+
"__tempId"
|
|
1378
|
+
]), INTERNAL_PROPERTIES = new Set([...BACKEND_PROPERTIES, ...FRONTEND_PROPERTIES]);
|
|
1379
|
+
function isInternalProperty(o) {
|
|
1380
|
+
return o === "__signedIdentifier" ? !1 : INTERNAL_PROPERTIES.has(o) ? !0 : o.startsWith("__");
|
|
1381
|
+
}
|
|
1382
|
+
function serializeTemporalValue(o, F) {
|
|
1383
|
+
switch (F) {
|
|
1384
|
+
case "date": return `${o.getFullYear()}-${String(o.getMonth() + 1).padStart(2, "0")}-${String(o.getDate()).padStart(2, "0")}`;
|
|
1385
|
+
case "timestamp": return o.toISOString();
|
|
1386
|
+
case "time": return `${String(o.getHours()).padStart(2, "0")}:${String(o.getMinutes()).padStart(2, "0")}:${String(o.getSeconds()).padStart(2, "0")}`;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
function createModelAwareSerializer(o) {
|
|
1390
|
+
return { serialize(F) {
|
|
1391
|
+
if (typeof F != "object" || !F) return F;
|
|
1392
|
+
if (Array.isArray(F)) return F.map((o) => this.serialize(o));
|
|
1393
|
+
let I = F, L = I.__entityType, R = L ? o[L] : void 0, z = {};
|
|
1394
|
+
for (let [o, F] of Object.entries(I)) if (!isInternalProperty(o)) if (F instanceof Date) {
|
|
1395
|
+
let I = R?.[o];
|
|
1396
|
+
z[o] = I ? serializeTemporalValue(F, I) : F.toISOString();
|
|
1397
|
+
} else typeof F == "object" && F ? z[o] = this.serialize(F) : z[o] = F;
|
|
1398
|
+
return z;
|
|
1399
|
+
} };
|
|
1400
|
+
}
|
|
1401
|
+
function parseLocalDate(o) {
|
|
1402
|
+
let F = o.split("-");
|
|
1403
|
+
if (F.length !== 3) return /* @__PURE__ */ new Date(NaN);
|
|
1404
|
+
let [I, L, R] = F.map(Number);
|
|
1405
|
+
return new Date(I, L - 1, R);
|
|
1406
|
+
}
|
|
1407
|
+
function deserializeTemporalValue(o, F) {
|
|
1408
|
+
switch (F) {
|
|
1409
|
+
case "date": return parseLocalDate(o);
|
|
1410
|
+
case "timestamp": return new Date(o);
|
|
1411
|
+
case "time": return o;
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
function createModelAwareDeserializer(o) {
|
|
1415
|
+
return { deserialize(F) {
|
|
1416
|
+
if (typeof F != "object" || !F) return F;
|
|
1417
|
+
if (Array.isArray(F)) return F.map((o) => this.deserialize(o));
|
|
1418
|
+
let I = F, L = I.__entityType, R = L ? o[L] : void 0, z = { ...I };
|
|
1419
|
+
for (let [o, F] of Object.entries(z)) typeof F == "object" && F && (z[o] = this.deserialize(F));
|
|
1420
|
+
if (R) for (let [o, F] of Object.entries(R)) {
|
|
1421
|
+
let I = z[o];
|
|
1422
|
+
typeof I == "string" && (z[o] = deserializeTemporalValue(I, F));
|
|
1423
|
+
}
|
|
1424
|
+
return z;
|
|
1425
|
+
} };
|
|
1426
|
+
}
|
|
1427
|
+
export { ACTION_HANDLER_FACTORY, ApiProvider, DEFAULT_COMMAND_MASK, HEADER_MARK_SELECTED_RANGE_ITEMS, HEADER_MASK, HEADER_SIGNED_IDENTIFIER, HEADER_TOKEN, JudoRestApi, SUFFIX_ADD, SUFFIX_CREATE, SUFFIX_DELETE, SUFFIX_EXPORT, SUFFIX_GET, SUFFIX_LIST, SUFFIX_RANGE, SUFFIX_REMOVE, SUFFIX_SET, SUFFIX_TEMPLATE, SUFFIX_UNSET, SUFFIX_UPDATE, SUFFIX_VALIDATE, ValidationError, createJudoRestApi, createModelAwareDeserializer, createModelAwareSerializer, deserializeTemporalValue, executeWithLifecycle, getActionHandler, getClassPath, getMutationRelationPath, getOperationPath, getPathForActor, getRelationPath, hasActionHandler, hasActionHandler$1 as hasActionHandlerRegistry, parseLocalDate, serializeTemporalValue, useActionDispatcher, useActionHandler, useAddActionHandler, useApi, useAutocompleteAddActionHandler, useAutocompleteRangeActionHandler, useAutocompleteSetActionHandler, useBackActionHandler, useBulkCallOperationActionHandler, useBulkDeleteActionHandler, useBulkRemoveActionHandler, useCallOperationActionHandler, useCancelActionHandler, useClearActionHandler, useCreateActionHandler, useCustomActionHandler, useDeleteActionHandler, useExportActionHandler, useFilterActionHandler, useFilterRelationActionHandler, useGetTemplateActionHandler, useInlineCreateRowActionHandler, useInputFormCallOperationActionHandler, useInputSelectorCallOperationActionHandler, useOpenAddSelectorActionHandler, useOpenCreateFormActionHandler, useOpenFormActionHandler, useOpenOperationInputFormActionHandler, useOpenOperationInputSelectorActionHandler, useOpenPageActionHandler, useOpenSelectorActionHandler, useOpenSetSelectorActionHandler, useParameterlessCallOperationActionHandler, usePreFetchActionHandler, useRefreshActionHandler, useRefreshRelationActionHandler, useRemoveActionHandler, useRowDeleteActionHandler, useRowOpenPageActionHandler, useSelectorRangeActionHandler, useSetActionHandler, useUnsetActionHandler, useUpdateActionHandler };
|