@elqnt/entity 1.0.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/dist/index.d.mts +730 -0
- package/dist/index.d.ts +730 -0
- package/dist/index.js +1218 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1108 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +44 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// index.tsx
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
EntityDefinitionContext: () => EntityDefinitionContext,
|
|
24
|
+
EntityDefinitionCreate: () => EntityDefinitionCreate,
|
|
25
|
+
EntityDefinitionCreated: () => EntityDefinitionCreated,
|
|
26
|
+
EntityDefinitionDelete: () => EntityDefinitionDelete,
|
|
27
|
+
EntityDefinitionDeleted: () => EntityDefinitionDeleted,
|
|
28
|
+
EntityDefinitionGet: () => EntityDefinitionGet,
|
|
29
|
+
EntityDefinitionGetServer: () => EntityDefinitionGetServer,
|
|
30
|
+
EntityDefinitionList: () => EntityDefinitionList,
|
|
31
|
+
EntityDefinitionProvider: () => EntityDefinitionProvider,
|
|
32
|
+
EntityDefinitionUpdate: () => EntityDefinitionUpdate,
|
|
33
|
+
EntityDefinitionUpdated: () => EntityDefinitionUpdated,
|
|
34
|
+
EntityFieldTypeBool: () => EntityFieldTypeBool,
|
|
35
|
+
EntityFieldTypeCurrency: () => EntityFieldTypeCurrency,
|
|
36
|
+
EntityFieldTypeDate: () => EntityFieldTypeDate,
|
|
37
|
+
EntityFieldTypeDateTime: () => EntityFieldTypeDateTime,
|
|
38
|
+
EntityFieldTypeDropdown: () => EntityFieldTypeDropdown,
|
|
39
|
+
EntityFieldTypeEmail: () => EntityFieldTypeEmail,
|
|
40
|
+
EntityFieldTypeFile: () => EntityFieldTypeFile,
|
|
41
|
+
EntityFieldTypeFloat: () => EntityFieldTypeFloat,
|
|
42
|
+
EntityFieldTypeImage: () => EntityFieldTypeImage,
|
|
43
|
+
EntityFieldTypeInt: () => EntityFieldTypeInt,
|
|
44
|
+
EntityFieldTypeJSON: () => EntityFieldTypeJSON,
|
|
45
|
+
EntityFieldTypeLookup: () => EntityFieldTypeLookup,
|
|
46
|
+
EntityFieldTypeMultiLookup: () => EntityFieldTypeMultiLookup,
|
|
47
|
+
EntityFieldTypeMultiSelect: () => EntityFieldTypeMultiSelect,
|
|
48
|
+
EntityFieldTypePhone: () => EntityFieldTypePhone,
|
|
49
|
+
EntityFieldTypeString: () => EntityFieldTypeString,
|
|
50
|
+
EntityFieldTypeStringMultiline: () => EntityFieldTypeStringMultiline,
|
|
51
|
+
EntityFieldTypeText: () => EntityFieldTypeText,
|
|
52
|
+
EntityFieldTypeURL: () => EntityFieldTypeURL,
|
|
53
|
+
EntityFieldTypes: () => EntityFieldTypes,
|
|
54
|
+
EntityFilterOperators: () => EntityFilterOperators,
|
|
55
|
+
EntityOrgSchemaCreate: () => EntityOrgSchemaCreate,
|
|
56
|
+
EntityOrgSchemaDrop: () => EntityOrgSchemaDrop,
|
|
57
|
+
EntityRecordContext: () => EntityRecordContext,
|
|
58
|
+
EntityRecordCount: () => EntityRecordCount,
|
|
59
|
+
EntityRecordCreate: () => EntityRecordCreate,
|
|
60
|
+
EntityRecordCreated: () => EntityRecordCreated,
|
|
61
|
+
EntityRecordDelete: () => EntityRecordDelete,
|
|
62
|
+
EntityRecordDeleted: () => EntityRecordDeleted,
|
|
63
|
+
EntityRecordGet: () => EntityRecordGet,
|
|
64
|
+
EntityRecordProvider: () => EntityRecordProvider,
|
|
65
|
+
EntityRecordQuery: () => EntityRecordQuery,
|
|
66
|
+
EntityRecordUpdate: () => EntityRecordUpdate,
|
|
67
|
+
EntityRecordUpdated: () => EntityRecordUpdated,
|
|
68
|
+
EntityRecordsBulkCreate: () => EntityRecordsBulkCreate,
|
|
69
|
+
EntityRecordsBulkCreated: () => EntityRecordsBulkCreated,
|
|
70
|
+
EntityRecordsBulkDelete: () => EntityRecordsBulkDelete,
|
|
71
|
+
EntityRecordsBulkDeleted: () => EntityRecordsBulkDeleted,
|
|
72
|
+
EntityRecordsBulkUpdate: () => EntityRecordsBulkUpdate,
|
|
73
|
+
EntityRecordsBulkUpdated: () => EntityRecordsBulkUpdated,
|
|
74
|
+
EntityViewCreate: () => EntityViewCreate,
|
|
75
|
+
EntityViewCreated: () => EntityViewCreated,
|
|
76
|
+
EntityViewDelete: () => EntityViewDelete,
|
|
77
|
+
EntityViewDeleted: () => EntityViewDeleted,
|
|
78
|
+
EntityViewList: () => EntityViewList,
|
|
79
|
+
EntityViewUpdate: () => EntityViewUpdate,
|
|
80
|
+
EntityViewUpdated: () => EntityViewUpdated,
|
|
81
|
+
OperatorBetween: () => OperatorBetween,
|
|
82
|
+
OperatorContains: () => OperatorContains,
|
|
83
|
+
OperatorEmpty: () => OperatorEmpty,
|
|
84
|
+
OperatorEndsWith: () => OperatorEndsWith,
|
|
85
|
+
OperatorEq: () => OperatorEq,
|
|
86
|
+
OperatorExists: () => OperatorExists,
|
|
87
|
+
OperatorGt: () => OperatorGt,
|
|
88
|
+
OperatorGte: () => OperatorGte,
|
|
89
|
+
OperatorIn: () => OperatorIn,
|
|
90
|
+
OperatorLt: () => OperatorLt,
|
|
91
|
+
OperatorLte: () => OperatorLte,
|
|
92
|
+
OperatorNe: () => OperatorNe,
|
|
93
|
+
OperatorNin: () => OperatorNin,
|
|
94
|
+
OperatorStartsWith: () => OperatorStartsWith,
|
|
95
|
+
PREDEFINED_COLORS: () => PREDEFINED_COLORS,
|
|
96
|
+
RecordChangeActionCreated: () => RecordChangeActionCreated,
|
|
97
|
+
RecordChangeActionDeleted: () => RecordChangeActionDeleted,
|
|
98
|
+
RecordChangeActionUpdated: () => RecordChangeActionUpdated,
|
|
99
|
+
entityDefinitionReducer: () => entityDefinitionReducer,
|
|
100
|
+
entityRecordReducer: () => entityRecordReducer,
|
|
101
|
+
useDebounce: () => useDebounce,
|
|
102
|
+
useEntityDefinition: () => useEntityDefinition,
|
|
103
|
+
useEntityDefinitionContext: () => useEntityDefinitionContext,
|
|
104
|
+
useEntityDefinitionDetails: () => useEntityDefinitionDetails,
|
|
105
|
+
useEntityRecord: () => useEntityRecord,
|
|
106
|
+
useEntityRecordContext: () => useEntityRecordContext
|
|
107
|
+
});
|
|
108
|
+
module.exports = __toCommonJS(index_exports);
|
|
109
|
+
|
|
110
|
+
// context/entity-definition-context.tsx
|
|
111
|
+
var import_react5 = require("react");
|
|
112
|
+
|
|
113
|
+
// hooks/use-entity-definition.ts
|
|
114
|
+
var import_react = require("react");
|
|
115
|
+
var import_react_redux = require("react-redux");
|
|
116
|
+
var import_nats = require("@elqnt/nats");
|
|
117
|
+
|
|
118
|
+
// models/entity.ts
|
|
119
|
+
var OperatorEq = "eq";
|
|
120
|
+
var OperatorNe = "ne";
|
|
121
|
+
var OperatorGt = "gt";
|
|
122
|
+
var OperatorGte = "gte";
|
|
123
|
+
var OperatorLt = "lt";
|
|
124
|
+
var OperatorLte = "lte";
|
|
125
|
+
var OperatorIn = "in";
|
|
126
|
+
var OperatorNin = "nin";
|
|
127
|
+
var OperatorContains = "contains";
|
|
128
|
+
var OperatorStartsWith = "startsWith";
|
|
129
|
+
var OperatorEndsWith = "endsWith";
|
|
130
|
+
var OperatorExists = "exists";
|
|
131
|
+
var OperatorEmpty = "empty";
|
|
132
|
+
var OperatorBetween = "between";
|
|
133
|
+
var EntityFilterOperators = {
|
|
134
|
+
eq: { value: "eq", label: "Equal to" },
|
|
135
|
+
ne: { value: "ne", label: "Not equal to" },
|
|
136
|
+
gt: { value: "gt", label: "Greater than" },
|
|
137
|
+
gte: { value: "gte", label: "Greater than or equal to" },
|
|
138
|
+
lt: { value: "lt", label: "Less than" },
|
|
139
|
+
lte: { value: "lte", label: "Less than or equal to" },
|
|
140
|
+
in: { value: "in", label: "In" },
|
|
141
|
+
nin: { value: "nin", label: "Not in" },
|
|
142
|
+
contains: { value: "contains", label: "Contains" },
|
|
143
|
+
startsWith: { value: "startsWith", label: "Starts with" },
|
|
144
|
+
endsWith: { value: "endsWith", label: "Ends with" },
|
|
145
|
+
exists: { value: "exists", label: "Exists" },
|
|
146
|
+
empty: { value: "empty", label: "Empty" },
|
|
147
|
+
between: { value: "between", label: "Between" }
|
|
148
|
+
};
|
|
149
|
+
var EntityFieldTypeString = "string";
|
|
150
|
+
var EntityFieldTypeStringMultiline = "stringMultiline";
|
|
151
|
+
var EntityFieldTypeText = "text";
|
|
152
|
+
var EntityFieldTypeInt = "int";
|
|
153
|
+
var EntityFieldTypeFloat = "float";
|
|
154
|
+
var EntityFieldTypeBool = "bool";
|
|
155
|
+
var EntityFieldTypeDate = "date";
|
|
156
|
+
var EntityFieldTypeDateTime = "datetime";
|
|
157
|
+
var EntityFieldTypeEmail = "email";
|
|
158
|
+
var EntityFieldTypePhone = "phone";
|
|
159
|
+
var EntityFieldTypeURL = "url";
|
|
160
|
+
var EntityFieldTypeDropdown = "dropdown";
|
|
161
|
+
var EntityFieldTypeMultiSelect = "multiselect";
|
|
162
|
+
var EntityFieldTypeLookup = "lookup";
|
|
163
|
+
var EntityFieldTypeMultiLookup = "multilookup";
|
|
164
|
+
var EntityFieldTypeCurrency = "currency";
|
|
165
|
+
var EntityFieldTypeFile = "file";
|
|
166
|
+
var EntityFieldTypeImage = "image";
|
|
167
|
+
var EntityFieldTypeJSON = "json";
|
|
168
|
+
var EntityFieldTypes = {
|
|
169
|
+
string: { value: "string", label: "Short Text" },
|
|
170
|
+
stringMultiline: { value: "stringMultiline", label: "Long Text" },
|
|
171
|
+
text: { value: "text", label: "Rich Text Editor" },
|
|
172
|
+
int: { value: "int", label: "Integer" },
|
|
173
|
+
float: { value: "float", label: "Decimal" },
|
|
174
|
+
bool: { value: "bool", label: "Boolean" },
|
|
175
|
+
date: { value: "date", label: "Date" },
|
|
176
|
+
datetime: { value: "datetime", label: "Date & Time" },
|
|
177
|
+
email: { value: "email", label: "Email" },
|
|
178
|
+
phone: { value: "phone", label: "Phone" },
|
|
179
|
+
url: { value: "url", label: "URL" },
|
|
180
|
+
dropdown: { value: "dropdown", label: "Dropdown" },
|
|
181
|
+
multiselect: { value: "multiselect", label: "Multi Select" },
|
|
182
|
+
lookup: { value: "lookup", label: "Lookup" },
|
|
183
|
+
multilookup: { value: "multilookup", label: "Multi Lookup" },
|
|
184
|
+
currency: { value: "currency", label: "Currency" },
|
|
185
|
+
file: { value: "file", label: "File" },
|
|
186
|
+
image: { value: "image", label: "Image" },
|
|
187
|
+
json: { value: "json", label: "JSON" }
|
|
188
|
+
};
|
|
189
|
+
var RecordChangeActionCreated = "created";
|
|
190
|
+
var RecordChangeActionUpdated = "updated";
|
|
191
|
+
var RecordChangeActionDeleted = "deleted";
|
|
192
|
+
var EntityOrgSchemaCreate = "entity.org.schema.create";
|
|
193
|
+
var EntityOrgSchemaDrop = "entity.org.schema.drop";
|
|
194
|
+
var EntityDefinitionCreate = "entity.definition.create";
|
|
195
|
+
var EntityDefinitionCreated = "entity.definition.created";
|
|
196
|
+
var EntityDefinitionUpdate = "entity.definition.update";
|
|
197
|
+
var EntityDefinitionGet = "entity.definition.get";
|
|
198
|
+
var EntityDefinitionGetServer = "entity.definition.get.server";
|
|
199
|
+
var EntityDefinitionList = "entity.definition.list";
|
|
200
|
+
var EntityDefinitionUpdated = "entity.definition.updated";
|
|
201
|
+
var EntityDefinitionDelete = "entity.definition.delete";
|
|
202
|
+
var EntityDefinitionDeleted = "entity.definition.deleted";
|
|
203
|
+
var EntityRecordCreate = "entity.record.create";
|
|
204
|
+
var EntityRecordCreated = "entity.record.created";
|
|
205
|
+
var EntityRecordGet = "entity.record.get";
|
|
206
|
+
var EntityRecordQuery = "entity.record.query";
|
|
207
|
+
var EntityRecordCount = "entity.record.count";
|
|
208
|
+
var EntityRecordUpdate = "entity.record.update";
|
|
209
|
+
var EntityRecordUpdated = "entity.record.updated";
|
|
210
|
+
var EntityRecordDelete = "entity.record.delete";
|
|
211
|
+
var EntityRecordDeleted = "entity.record.deleted";
|
|
212
|
+
var EntityRecordsBulkCreate = "entity.records.bulk.create";
|
|
213
|
+
var EntityRecordsBulkCreated = "entity.records.bulk.created";
|
|
214
|
+
var EntityRecordsBulkUpdate = "entity.records.bulk.update";
|
|
215
|
+
var EntityRecordsBulkUpdated = "entity.records.bulk.updated";
|
|
216
|
+
var EntityRecordsBulkDelete = "entity.records.bulk.delete";
|
|
217
|
+
var EntityRecordsBulkDeleted = "entity.records.bulk.deleted";
|
|
218
|
+
var EntityViewCreate = "entity.view.create";
|
|
219
|
+
var EntityViewCreated = "entity.view.created";
|
|
220
|
+
var EntityViewUpdate = "entity.view.update";
|
|
221
|
+
var EntityViewUpdated = "entity.view.updated";
|
|
222
|
+
var EntityViewDelete = "entity.view.delete";
|
|
223
|
+
var EntityViewDeleted = "entity.view.deleted";
|
|
224
|
+
var EntityViewList = "entity.view.list";
|
|
225
|
+
|
|
226
|
+
// store/entity-definition-slice.ts
|
|
227
|
+
var import_toolkit = require("@reduxjs/toolkit");
|
|
228
|
+
var initialState = {
|
|
229
|
+
definitions: {},
|
|
230
|
+
views: {},
|
|
231
|
+
isLoading: false,
|
|
232
|
+
loadingStates: {}
|
|
233
|
+
};
|
|
234
|
+
var entityDefinitionSlice = (0, import_toolkit.createSlice)({
|
|
235
|
+
name: "entityDefinition",
|
|
236
|
+
initialState,
|
|
237
|
+
reducers: {
|
|
238
|
+
setLoading: (state, action) => {
|
|
239
|
+
state.isLoading = action.payload;
|
|
240
|
+
},
|
|
241
|
+
setOperationLoading: (state, action) => {
|
|
242
|
+
state.loadingStates[action.payload.operation] = action.payload.loading;
|
|
243
|
+
},
|
|
244
|
+
setError: (state, action) => {
|
|
245
|
+
state.error = action.payload;
|
|
246
|
+
},
|
|
247
|
+
setDefinitions: (state, action) => {
|
|
248
|
+
state.definitions = action.payload.reduce(
|
|
249
|
+
(acc, def) => {
|
|
250
|
+
acc[def.name] = def;
|
|
251
|
+
return acc;
|
|
252
|
+
},
|
|
253
|
+
{}
|
|
254
|
+
);
|
|
255
|
+
},
|
|
256
|
+
addDefinition: (state, action) => {
|
|
257
|
+
const definition = action.payload;
|
|
258
|
+
state.definitions[definition.name] = definition;
|
|
259
|
+
},
|
|
260
|
+
updateDefinition: (state, action) => {
|
|
261
|
+
const definition = action.payload;
|
|
262
|
+
state.definitions[definition.name] = definition;
|
|
263
|
+
if (state.selectedDefinition?.name === definition.name) {
|
|
264
|
+
state.selectedDefinition = definition;
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
removeDefinition: (state, action) => {
|
|
268
|
+
delete state.definitions[action.payload];
|
|
269
|
+
if (state.selectedDefinition?.name === action.payload) {
|
|
270
|
+
state.selectedDefinition = void 0;
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
setSelectedDefinition: (state, action) => {
|
|
274
|
+
state.selectedDefinition = action.payload;
|
|
275
|
+
},
|
|
276
|
+
setViews: (state, action) => {
|
|
277
|
+
const { entityName, views } = action.payload;
|
|
278
|
+
state.views[entityName] = views;
|
|
279
|
+
},
|
|
280
|
+
addView: (state, action) => {
|
|
281
|
+
const { entityName, view } = action.payload;
|
|
282
|
+
if (!state.views[entityName]) {
|
|
283
|
+
state.views[entityName] = [];
|
|
284
|
+
}
|
|
285
|
+
state.views[entityName].push(view);
|
|
286
|
+
},
|
|
287
|
+
updateView: (state, action) => {
|
|
288
|
+
const { entityName, view } = action.payload;
|
|
289
|
+
const views = state.views[entityName];
|
|
290
|
+
if (views) {
|
|
291
|
+
const index = views.findIndex((v) => v.id === view.id);
|
|
292
|
+
if (index !== -1) {
|
|
293
|
+
views[index] = view;
|
|
294
|
+
if (state.selectedView?.id === view.id) {
|
|
295
|
+
state.selectedView = view;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
removeView: (state, action) => {
|
|
301
|
+
const { entityName, viewId } = action.payload;
|
|
302
|
+
const views = state.views[entityName];
|
|
303
|
+
if (views) {
|
|
304
|
+
state.views[entityName] = views.filter((v) => v.id !== viewId);
|
|
305
|
+
if (state.selectedView?.id === viewId) {
|
|
306
|
+
state.selectedView = void 0;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
setSelectedView: (state, action) => {
|
|
311
|
+
state.selectedView = action.payload;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
var {
|
|
316
|
+
setLoading,
|
|
317
|
+
setOperationLoading,
|
|
318
|
+
setError,
|
|
319
|
+
setDefinitions,
|
|
320
|
+
addDefinition,
|
|
321
|
+
updateDefinition,
|
|
322
|
+
removeDefinition,
|
|
323
|
+
setSelectedDefinition,
|
|
324
|
+
setViews,
|
|
325
|
+
addView,
|
|
326
|
+
updateView,
|
|
327
|
+
removeView,
|
|
328
|
+
setSelectedView
|
|
329
|
+
} = entityDefinitionSlice.actions;
|
|
330
|
+
var entityDefinitionReducer = entityDefinitionSlice.reducer;
|
|
331
|
+
|
|
332
|
+
// hooks/use-entity-definition.ts
|
|
333
|
+
function useEntityDefinition(orgId, entityName, options = {}) {
|
|
334
|
+
const { autoLoad, module: module2 } = options;
|
|
335
|
+
const { natsConnected, request } = (0, import_nats.useNatsContext)();
|
|
336
|
+
const dispatch = (0, import_react_redux.useDispatch)();
|
|
337
|
+
const definitions = (0, import_react_redux.useSelector)(
|
|
338
|
+
(state) => state.entityDefinition.definitions
|
|
339
|
+
);
|
|
340
|
+
const selectedDefinition = (0, import_react_redux.useSelector)(
|
|
341
|
+
(state) => state.entityDefinition.selectedDefinition
|
|
342
|
+
);
|
|
343
|
+
const views = (0, import_react_redux.useSelector)(
|
|
344
|
+
(state) => state.entityDefinition.views
|
|
345
|
+
);
|
|
346
|
+
const selectedView = (0, import_react_redux.useSelector)(
|
|
347
|
+
(state) => state.entityDefinition.selectedView
|
|
348
|
+
);
|
|
349
|
+
const isLoading = (0, import_react_redux.useSelector)(
|
|
350
|
+
(state) => state.entityDefinition.isLoading
|
|
351
|
+
);
|
|
352
|
+
const loadingStates = (0, import_react_redux.useSelector)(
|
|
353
|
+
(state) => state.entityDefinition.loadingStates
|
|
354
|
+
);
|
|
355
|
+
const error = (0, import_react_redux.useSelector)(
|
|
356
|
+
(state) => state.entityDefinition.error
|
|
357
|
+
);
|
|
358
|
+
const createOrgSchema = (0, import_react.useCallback)(
|
|
359
|
+
async (targetOrgId) => {
|
|
360
|
+
if (!natsConnected) {
|
|
361
|
+
throw new Error("Not connected to NATS");
|
|
362
|
+
}
|
|
363
|
+
dispatch(setOperationLoading({ operation: "createOrgSchema", loading: true }));
|
|
364
|
+
try {
|
|
365
|
+
const response = await request(EntityOrgSchemaCreate, { orgId: targetOrgId });
|
|
366
|
+
if (response instanceof Error) {
|
|
367
|
+
throw response;
|
|
368
|
+
}
|
|
369
|
+
return response;
|
|
370
|
+
} finally {
|
|
371
|
+
dispatch(setOperationLoading({ operation: "createOrgSchema", loading: false }));
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
[natsConnected, dispatch, request]
|
|
375
|
+
);
|
|
376
|
+
const dropOrgSchema = (0, import_react.useCallback)(
|
|
377
|
+
async (targetOrgId) => {
|
|
378
|
+
if (!natsConnected) {
|
|
379
|
+
throw new Error("Not connected to NATS");
|
|
380
|
+
}
|
|
381
|
+
dispatch(setOperationLoading({ operation: "dropOrgSchema", loading: true }));
|
|
382
|
+
try {
|
|
383
|
+
const response = await request(EntityOrgSchemaDrop, { orgId: targetOrgId });
|
|
384
|
+
if (response instanceof Error) {
|
|
385
|
+
throw response;
|
|
386
|
+
}
|
|
387
|
+
return response;
|
|
388
|
+
} finally {
|
|
389
|
+
dispatch(setOperationLoading({ operation: "dropOrgSchema", loading: false }));
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
[natsConnected, dispatch, request]
|
|
393
|
+
);
|
|
394
|
+
const loadDefinitions = (0, import_react.useCallback)(async () => {
|
|
395
|
+
if (!natsConnected || !orgId) return;
|
|
396
|
+
const loadingKey = "loadDefinitions";
|
|
397
|
+
if (loadingStates[loadingKey]) return;
|
|
398
|
+
dispatch(setOperationLoading({ operation: loadingKey, loading: true }));
|
|
399
|
+
try {
|
|
400
|
+
const response = await request(EntityDefinitionList, { orgId, module: module2 });
|
|
401
|
+
if (response instanceof Error) {
|
|
402
|
+
dispatch(setError(response.message));
|
|
403
|
+
} else {
|
|
404
|
+
dispatch(setDefinitions(response?.definitions ?? []));
|
|
405
|
+
}
|
|
406
|
+
} catch (err) {
|
|
407
|
+
dispatch(setError(err instanceof Error ? err.message : "Unknown error"));
|
|
408
|
+
} finally {
|
|
409
|
+
dispatch(setOperationLoading({ operation: loadingKey, loading: false }));
|
|
410
|
+
}
|
|
411
|
+
}, [natsConnected, orgId, options.module, dispatch, request]);
|
|
412
|
+
(0, import_react.useEffect)(() => {
|
|
413
|
+
let mounted = true;
|
|
414
|
+
if (autoLoad && natsConnected && orgId && mounted) {
|
|
415
|
+
loadDefinitions();
|
|
416
|
+
}
|
|
417
|
+
return () => {
|
|
418
|
+
mounted = false;
|
|
419
|
+
};
|
|
420
|
+
}, [autoLoad, natsConnected, orgId]);
|
|
421
|
+
const loadDefinition = (0, import_react.useCallback)(
|
|
422
|
+
async (name) => {
|
|
423
|
+
if (!natsConnected || !orgId) return;
|
|
424
|
+
dispatch(
|
|
425
|
+
setOperationLoading({ operation: `load_${name}`, loading: true })
|
|
426
|
+
);
|
|
427
|
+
try {
|
|
428
|
+
const response = await request(EntityDefinitionGet, { entityName: name, orgId }, {});
|
|
429
|
+
if (response instanceof Error) {
|
|
430
|
+
dispatch(setError(response.message));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
dispatch(setSelectedDefinition(response.definition));
|
|
434
|
+
} finally {
|
|
435
|
+
dispatch(
|
|
436
|
+
setOperationLoading({ operation: `load_${name}`, loading: false })
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
[natsConnected, orgId, dispatch, request]
|
|
441
|
+
);
|
|
442
|
+
(0, import_react.useEffect)(() => {
|
|
443
|
+
if (natsConnected && orgId && entityName) {
|
|
444
|
+
loadDefinition(entityName);
|
|
445
|
+
}
|
|
446
|
+
}, [natsConnected, orgId, entityName, loadDefinition]);
|
|
447
|
+
const createDefinition = async (definition) => {
|
|
448
|
+
if (!natsConnected || !orgId) {
|
|
449
|
+
throw new Error("Not connected or missing orgId");
|
|
450
|
+
}
|
|
451
|
+
dispatch(setOperationLoading({ operation: "create", loading: true }));
|
|
452
|
+
try {
|
|
453
|
+
const response = await request(EntityDefinitionCreate, { definition, orgId }, {});
|
|
454
|
+
if (response instanceof Error) {
|
|
455
|
+
console.error("createDefinition error", response);
|
|
456
|
+
throw response;
|
|
457
|
+
}
|
|
458
|
+
if (response.metadata.success) {
|
|
459
|
+
dispatch(addDefinition(response.definition));
|
|
460
|
+
}
|
|
461
|
+
return response;
|
|
462
|
+
} finally {
|
|
463
|
+
dispatch(setOperationLoading({ operation: "create", loading: false }));
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
const updateDefinitionById = async (name, definition) => {
|
|
467
|
+
if (!natsConnected || !orgId) {
|
|
468
|
+
throw new Error("Not connected or missing orgId");
|
|
469
|
+
}
|
|
470
|
+
dispatch(
|
|
471
|
+
setOperationLoading({ operation: `update_${name}`, loading: true })
|
|
472
|
+
);
|
|
473
|
+
try {
|
|
474
|
+
const response = await request(
|
|
475
|
+
EntityDefinitionUpdate,
|
|
476
|
+
{
|
|
477
|
+
entityName: name,
|
|
478
|
+
definition,
|
|
479
|
+
orgId
|
|
480
|
+
},
|
|
481
|
+
{}
|
|
482
|
+
);
|
|
483
|
+
if (response instanceof Error) {
|
|
484
|
+
throw response;
|
|
485
|
+
}
|
|
486
|
+
if (response.metadata.success) {
|
|
487
|
+
dispatch(updateDefinition(response.definition));
|
|
488
|
+
}
|
|
489
|
+
return response;
|
|
490
|
+
} finally {
|
|
491
|
+
dispatch(
|
|
492
|
+
setOperationLoading({ operation: `update_${name}`, loading: false })
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
const deleteDefinition = async (name) => {
|
|
497
|
+
if (!natsConnected || !orgId) {
|
|
498
|
+
throw new Error("Not connected or missing orgId");
|
|
499
|
+
}
|
|
500
|
+
dispatch(
|
|
501
|
+
setOperationLoading({ operation: `delete_${name}`, loading: true })
|
|
502
|
+
);
|
|
503
|
+
try {
|
|
504
|
+
const response = await request(EntityDefinitionDelete, { entityName: name, orgId }, {});
|
|
505
|
+
if (response instanceof Error) {
|
|
506
|
+
throw response;
|
|
507
|
+
}
|
|
508
|
+
dispatch(removeDefinition(name));
|
|
509
|
+
return response;
|
|
510
|
+
} finally {
|
|
511
|
+
dispatch(
|
|
512
|
+
setOperationLoading({ operation: `delete_${name}`, loading: false })
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
const loadViews = (0, import_react.useCallback)(
|
|
517
|
+
async (entityName2) => {
|
|
518
|
+
if (!natsConnected || !orgId) return;
|
|
519
|
+
const loadingKey = `loadViews_${entityName2}`;
|
|
520
|
+
if (loadingStates[loadingKey]) return;
|
|
521
|
+
dispatch(setOperationLoading({ operation: loadingKey, loading: true }));
|
|
522
|
+
try {
|
|
523
|
+
const response = await request(
|
|
524
|
+
EntityViewList,
|
|
525
|
+
{ entityName: entityName2, orgId },
|
|
526
|
+
{}
|
|
527
|
+
);
|
|
528
|
+
console.log("loadViews response", response);
|
|
529
|
+
if (response instanceof Error) {
|
|
530
|
+
dispatch(setError(response.message));
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
dispatch(setViews({ entityName: entityName2, views: response.views }));
|
|
534
|
+
} catch (err) {
|
|
535
|
+
dispatch(
|
|
536
|
+
setError(err instanceof Error ? err.message : "Unknown error")
|
|
537
|
+
);
|
|
538
|
+
} finally {
|
|
539
|
+
dispatch(
|
|
540
|
+
setOperationLoading({ operation: loadingKey, loading: false })
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
[natsConnected, orgId, loadingStates, dispatch, request]
|
|
545
|
+
);
|
|
546
|
+
const createView = async (entityName2, view) => {
|
|
547
|
+
if (!natsConnected || !orgId) {
|
|
548
|
+
throw new Error("Not connected or missing orgId");
|
|
549
|
+
}
|
|
550
|
+
dispatch(setOperationLoading({ operation: "create_view", loading: true }));
|
|
551
|
+
try {
|
|
552
|
+
const response = await request(
|
|
553
|
+
EntityViewCreate,
|
|
554
|
+
{ entityName: entityName2, view, orgId },
|
|
555
|
+
{}
|
|
556
|
+
);
|
|
557
|
+
if (response instanceof Error) {
|
|
558
|
+
throw response;
|
|
559
|
+
}
|
|
560
|
+
dispatch(addView({ entityName: entityName2, view: response.view }));
|
|
561
|
+
return response.view;
|
|
562
|
+
} finally {
|
|
563
|
+
dispatch(
|
|
564
|
+
setOperationLoading({ operation: "create_view", loading: false })
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const updateViewById = async (entityName2, view) => {
|
|
569
|
+
if (!natsConnected || !orgId || !view.id) {
|
|
570
|
+
throw new Error("Not connected, missing orgId, or invalid view");
|
|
571
|
+
}
|
|
572
|
+
dispatch(
|
|
573
|
+
setOperationLoading({
|
|
574
|
+
operation: `update_view_${view.id}`,
|
|
575
|
+
loading: true
|
|
576
|
+
})
|
|
577
|
+
);
|
|
578
|
+
try {
|
|
579
|
+
const response = await request(
|
|
580
|
+
EntityViewUpdate,
|
|
581
|
+
{ view, orgId },
|
|
582
|
+
{}
|
|
583
|
+
);
|
|
584
|
+
if (response instanceof Error) {
|
|
585
|
+
throw response;
|
|
586
|
+
}
|
|
587
|
+
dispatch(updateView({ entityName: entityName2, view: response.view }));
|
|
588
|
+
return response.view;
|
|
589
|
+
} finally {
|
|
590
|
+
dispatch(
|
|
591
|
+
setOperationLoading({
|
|
592
|
+
operation: `update_view_${view.id}`,
|
|
593
|
+
loading: false
|
|
594
|
+
})
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
};
|
|
598
|
+
const deleteView = async (entityName2, viewId) => {
|
|
599
|
+
if (!natsConnected || !orgId) {
|
|
600
|
+
throw new Error("Not connected or missing orgId");
|
|
601
|
+
}
|
|
602
|
+
dispatch(
|
|
603
|
+
setOperationLoading({ operation: `delete_view_${viewId}`, loading: true })
|
|
604
|
+
);
|
|
605
|
+
try {
|
|
606
|
+
const response = await request(
|
|
607
|
+
EntityViewDelete,
|
|
608
|
+
{ viewId, orgId },
|
|
609
|
+
{}
|
|
610
|
+
);
|
|
611
|
+
if (response instanceof Error) {
|
|
612
|
+
throw response;
|
|
613
|
+
}
|
|
614
|
+
dispatch(removeView({ entityName: entityName2, viewId }));
|
|
615
|
+
return response;
|
|
616
|
+
} finally {
|
|
617
|
+
dispatch(
|
|
618
|
+
setOperationLoading({
|
|
619
|
+
operation: `delete_view_${viewId}`,
|
|
620
|
+
loading: false
|
|
621
|
+
})
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
const refresh = (0, import_react.useCallback)(() => {
|
|
626
|
+
if (!natsConnected || !orgId) return;
|
|
627
|
+
if (entityName) {
|
|
628
|
+
loadDefinition(entityName);
|
|
629
|
+
} else {
|
|
630
|
+
dispatch(setLoading(true));
|
|
631
|
+
loadDefinitions().finally(() => dispatch(setLoading(false)));
|
|
632
|
+
}
|
|
633
|
+
}, [natsConnected, orgId, entityName, loadDefinition, dispatch]);
|
|
634
|
+
return {
|
|
635
|
+
// State
|
|
636
|
+
definitions,
|
|
637
|
+
selectedDefinition,
|
|
638
|
+
views,
|
|
639
|
+
selectedView,
|
|
640
|
+
isLoading,
|
|
641
|
+
loadingStates,
|
|
642
|
+
error,
|
|
643
|
+
// Organization operations
|
|
644
|
+
createOrgSchema,
|
|
645
|
+
dropOrgSchema,
|
|
646
|
+
// Definition operations
|
|
647
|
+
loadDefinitions,
|
|
648
|
+
loadDefinition,
|
|
649
|
+
createDefinition,
|
|
650
|
+
updateDefinition: updateDefinitionById,
|
|
651
|
+
deleteDefinition,
|
|
652
|
+
// View operations
|
|
653
|
+
loadViews,
|
|
654
|
+
createView,
|
|
655
|
+
updateView: updateViewById,
|
|
656
|
+
deleteView,
|
|
657
|
+
// Utilities
|
|
658
|
+
refresh
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// hooks/use-entity-definition-details.ts
|
|
663
|
+
var import_react2 = require("react");
|
|
664
|
+
function useEntityDefinitionDetails(entityName) {
|
|
665
|
+
const context = useEntityDefinitionContext();
|
|
666
|
+
const definition = context.definitions[entityName];
|
|
667
|
+
const loadDefinitionDetails = (0, import_react2.useCallback)(async () => {
|
|
668
|
+
return context.loadDefinition(entityName);
|
|
669
|
+
}, [context, entityName]);
|
|
670
|
+
(0, import_react2.useEffect)(() => {
|
|
671
|
+
if (entityName && !definition) {
|
|
672
|
+
loadDefinitionDetails();
|
|
673
|
+
}
|
|
674
|
+
}, [definition, entityName, loadDefinitionDetails]);
|
|
675
|
+
return {
|
|
676
|
+
definition,
|
|
677
|
+
isLoading: context.loadingStates[`load_${entityName}`],
|
|
678
|
+
error: context.error,
|
|
679
|
+
updateDefinition: (updatedDef) => context.updateDefinition(entityName, updatedDef),
|
|
680
|
+
deleteDefinition: () => context.deleteDefinition(entityName),
|
|
681
|
+
refresh: loadDefinitionDetails
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// hooks/use-entity-record.ts
|
|
686
|
+
var import_react3 = require("react");
|
|
687
|
+
var import_react_redux2 = require("react-redux");
|
|
688
|
+
var import_nats2 = require("@elqnt/nats");
|
|
689
|
+
|
|
690
|
+
// store/entity-record-slice.ts
|
|
691
|
+
var import_toolkit2 = require("@reduxjs/toolkit");
|
|
692
|
+
var initialState2 = {
|
|
693
|
+
records: {},
|
|
694
|
+
isLoading: false,
|
|
695
|
+
loadingStates: {}
|
|
696
|
+
};
|
|
697
|
+
var entityRecordSlice = (0, import_toolkit2.createSlice)({
|
|
698
|
+
name: "entityRecord",
|
|
699
|
+
initialState: initialState2,
|
|
700
|
+
reducers: {
|
|
701
|
+
setLoading: (state, action) => {
|
|
702
|
+
state.isLoading = action.payload;
|
|
703
|
+
},
|
|
704
|
+
setOperationLoading: (state, action) => {
|
|
705
|
+
state.loadingStates[action.payload.operation] = action.payload.loading;
|
|
706
|
+
},
|
|
707
|
+
setError: (state, action) => {
|
|
708
|
+
state.error = action.payload;
|
|
709
|
+
},
|
|
710
|
+
setRecords: (state, action) => {
|
|
711
|
+
const { entityName, records, params } = action.payload;
|
|
712
|
+
state.records[entityName] = {
|
|
713
|
+
items: records.items.reduce(
|
|
714
|
+
(acc, record) => {
|
|
715
|
+
acc[record.id] = record;
|
|
716
|
+
return acc;
|
|
717
|
+
},
|
|
718
|
+
{}
|
|
719
|
+
),
|
|
720
|
+
params,
|
|
721
|
+
meta: records,
|
|
722
|
+
selected: []
|
|
723
|
+
};
|
|
724
|
+
},
|
|
725
|
+
addRecord: (state, action) => {
|
|
726
|
+
const { entityName, record } = action.payload;
|
|
727
|
+
if (state.records[entityName]) {
|
|
728
|
+
state.records[entityName].items[record.id] = record;
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
updateRecord: (state, action) => {
|
|
732
|
+
const { entityName, record } = action.payload;
|
|
733
|
+
if (state.records[entityName]) {
|
|
734
|
+
state.records[entityName].items[record.id] = record;
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
removeRecord: (state, action) => {
|
|
738
|
+
const { entityName, recordId } = action.payload;
|
|
739
|
+
if (state.records[entityName]) {
|
|
740
|
+
delete state.records[entityName].items[recordId];
|
|
741
|
+
state.records[entityName].selected = state.records[entityName].selected.filter((id) => id !== recordId);
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
setSelected: (state, action) => {
|
|
745
|
+
const { entityName, ids } = action.payload;
|
|
746
|
+
if (state.records[entityName]) {
|
|
747
|
+
state.records[entityName].selected = ids;
|
|
748
|
+
}
|
|
749
|
+
},
|
|
750
|
+
setActiveView: (state, action) => {
|
|
751
|
+
state.activeView = action.payload;
|
|
752
|
+
},
|
|
753
|
+
updateQueryParams: (state, action) => {
|
|
754
|
+
const { entityName, params } = action.payload;
|
|
755
|
+
if (state.records[entityName]) {
|
|
756
|
+
state.records[entityName].params = {
|
|
757
|
+
...state.records[entityName].params,
|
|
758
|
+
...params
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
},
|
|
762
|
+
setSelectedRecord: (state, action) => {
|
|
763
|
+
const { record } = action.payload;
|
|
764
|
+
state.selectedRecord = record;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
var {
|
|
769
|
+
setLoading: setLoading2,
|
|
770
|
+
setOperationLoading: setOperationLoading2,
|
|
771
|
+
setError: setError2,
|
|
772
|
+
setRecords,
|
|
773
|
+
addRecord,
|
|
774
|
+
updateRecord,
|
|
775
|
+
removeRecord,
|
|
776
|
+
setSelected,
|
|
777
|
+
setSelectedRecord,
|
|
778
|
+
setActiveView,
|
|
779
|
+
updateQueryParams
|
|
780
|
+
} = entityRecordSlice.actions;
|
|
781
|
+
var entityRecordReducer = entityRecordSlice.reducer;
|
|
782
|
+
|
|
783
|
+
// hooks/use-entity-record.ts
|
|
784
|
+
var defaultQuery = {
|
|
785
|
+
filters: {},
|
|
786
|
+
page: 1,
|
|
787
|
+
pageSize: 25,
|
|
788
|
+
sortBy: "metadata.createdAt",
|
|
789
|
+
sortOrder: -1
|
|
790
|
+
};
|
|
791
|
+
function useEntityRecord(orgId, entityName, options = {}) {
|
|
792
|
+
const { autoLoad = true } = options;
|
|
793
|
+
const { natsConnected, request } = (0, import_nats2.useNatsContext)();
|
|
794
|
+
const dispatch = (0, import_react_redux2.useDispatch)();
|
|
795
|
+
const recordState = (0, import_react_redux2.useSelector)(
|
|
796
|
+
(state) => state.entityRecord.records[entityName] || {
|
|
797
|
+
items: {},
|
|
798
|
+
params: defaultQuery,
|
|
799
|
+
meta: {
|
|
800
|
+
items: [],
|
|
801
|
+
totalCount: 0,
|
|
802
|
+
currentPage: 1,
|
|
803
|
+
pageSize: 25,
|
|
804
|
+
totalPages: 0
|
|
805
|
+
},
|
|
806
|
+
selected: []
|
|
807
|
+
}
|
|
808
|
+
);
|
|
809
|
+
const selectedRecord = (0, import_react_redux2.useSelector)(
|
|
810
|
+
(state) => state.entityRecord.selectedRecord
|
|
811
|
+
);
|
|
812
|
+
const isLoading = (0, import_react_redux2.useSelector)(
|
|
813
|
+
(state) => state.entityRecord.isLoading
|
|
814
|
+
);
|
|
815
|
+
const loadingStates = (0, import_react_redux2.useSelector)(
|
|
816
|
+
(state) => state.entityRecord.loadingStates
|
|
817
|
+
);
|
|
818
|
+
const error = (0, import_react_redux2.useSelector)(
|
|
819
|
+
(state) => state.entityRecord.error
|
|
820
|
+
);
|
|
821
|
+
const loadRecords = (0, import_react3.useCallback)(
|
|
822
|
+
async (params) => {
|
|
823
|
+
if (!natsConnected || !orgId) return;
|
|
824
|
+
const loadingKey = `load_${entityName}`;
|
|
825
|
+
if (loadingStates[loadingKey]) return;
|
|
826
|
+
dispatch(setOperationLoading2({ operation: loadingKey, loading: true }));
|
|
827
|
+
try {
|
|
828
|
+
const queryParams = { ...recordState.params, ...params };
|
|
829
|
+
const response = await request(
|
|
830
|
+
EntityRecordQuery,
|
|
831
|
+
{
|
|
832
|
+
orgId,
|
|
833
|
+
entityName,
|
|
834
|
+
query: queryParams
|
|
835
|
+
}
|
|
836
|
+
);
|
|
837
|
+
if (response instanceof Error) {
|
|
838
|
+
dispatch(setError2(response.message));
|
|
839
|
+
} else if (response.records) {
|
|
840
|
+
dispatch(
|
|
841
|
+
setRecords({
|
|
842
|
+
entityName,
|
|
843
|
+
records: response.records,
|
|
844
|
+
params: queryParams
|
|
845
|
+
})
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
} catch (err) {
|
|
849
|
+
dispatch(
|
|
850
|
+
setError2(err instanceof Error ? err.message : "Unknown error")
|
|
851
|
+
);
|
|
852
|
+
} finally {
|
|
853
|
+
dispatch(
|
|
854
|
+
setOperationLoading2({ operation: loadingKey, loading: false })
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
},
|
|
858
|
+
[natsConnected, orgId, entityName, recordState.params, dispatch, request]
|
|
859
|
+
);
|
|
860
|
+
const loadRecord = (0, import_react3.useCallback)(
|
|
861
|
+
async (recordId) => {
|
|
862
|
+
if (!natsConnected || !orgId) return;
|
|
863
|
+
const loadingKey = `load_${recordId}`;
|
|
864
|
+
if (loadingStates[loadingKey]) return;
|
|
865
|
+
dispatch(setOperationLoading2({ operation: loadingKey, loading: true }));
|
|
866
|
+
try {
|
|
867
|
+
const response = await request(EntityRecordGet, { entityName, recordId, orgId }, {});
|
|
868
|
+
if (response instanceof Error) {
|
|
869
|
+
dispatch(setError2(response.message));
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
dispatch(setSelectedRecord({ record: response.record }));
|
|
873
|
+
} finally {
|
|
874
|
+
dispatch(
|
|
875
|
+
setOperationLoading2({ operation: loadingKey, loading: false })
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
},
|
|
879
|
+
[natsConnected, orgId, entityName, recordState.params, dispatch, request]
|
|
880
|
+
);
|
|
881
|
+
const createRecord = async (record) => {
|
|
882
|
+
if (!natsConnected || !orgId) {
|
|
883
|
+
throw new Error("Not connected or missing orgId");
|
|
884
|
+
}
|
|
885
|
+
dispatch(
|
|
886
|
+
setOperationLoading2({ operation: "create_record", loading: true })
|
|
887
|
+
);
|
|
888
|
+
try {
|
|
889
|
+
const response = await request(
|
|
890
|
+
EntityRecordCreate,
|
|
891
|
+
{
|
|
892
|
+
orgId,
|
|
893
|
+
entityName,
|
|
894
|
+
record
|
|
895
|
+
}
|
|
896
|
+
);
|
|
897
|
+
if (response instanceof Error) {
|
|
898
|
+
throw response;
|
|
899
|
+
}
|
|
900
|
+
if (response.metadata.success) {
|
|
901
|
+
dispatch(addRecord({ entityName, record: response.record }));
|
|
902
|
+
}
|
|
903
|
+
loadRecords();
|
|
904
|
+
return response;
|
|
905
|
+
} finally {
|
|
906
|
+
dispatch(
|
|
907
|
+
setOperationLoading2({ operation: "create_record", loading: false })
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
};
|
|
911
|
+
const updateRecordById = async (record) => {
|
|
912
|
+
if (!natsConnected || !orgId) {
|
|
913
|
+
throw new Error("Not connected or missing orgId");
|
|
914
|
+
}
|
|
915
|
+
dispatch(
|
|
916
|
+
setOperationLoading2({ operation: `update_${record.id}`, loading: true })
|
|
917
|
+
);
|
|
918
|
+
try {
|
|
919
|
+
const response = await request(
|
|
920
|
+
EntityRecordUpdate,
|
|
921
|
+
{
|
|
922
|
+
orgId,
|
|
923
|
+
entityName,
|
|
924
|
+
record,
|
|
925
|
+
recordId: record.id
|
|
926
|
+
}
|
|
927
|
+
);
|
|
928
|
+
if (response instanceof Error) {
|
|
929
|
+
throw response;
|
|
930
|
+
}
|
|
931
|
+
dispatch(updateRecord({ entityName, record: response.record }));
|
|
932
|
+
return response;
|
|
933
|
+
} finally {
|
|
934
|
+
dispatch(
|
|
935
|
+
setOperationLoading2({
|
|
936
|
+
operation: `update_${record.id}`,
|
|
937
|
+
loading: false
|
|
938
|
+
})
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
const deleteRecordById = async (recordId) => {
|
|
943
|
+
if (!natsConnected || !orgId) {
|
|
944
|
+
throw new Error("Not connected or missing orgId");
|
|
945
|
+
}
|
|
946
|
+
dispatch(
|
|
947
|
+
setOperationLoading2({ operation: `delete_${recordId}`, loading: true })
|
|
948
|
+
);
|
|
949
|
+
try {
|
|
950
|
+
const response = await request(
|
|
951
|
+
EntityRecordDelete,
|
|
952
|
+
{
|
|
953
|
+
orgId,
|
|
954
|
+
entityName,
|
|
955
|
+
recordId
|
|
956
|
+
}
|
|
957
|
+
);
|
|
958
|
+
if (response instanceof Error) {
|
|
959
|
+
throw response;
|
|
960
|
+
}
|
|
961
|
+
dispatch(removeRecord({ entityName, recordId }));
|
|
962
|
+
return response;
|
|
963
|
+
} finally {
|
|
964
|
+
dispatch(
|
|
965
|
+
setOperationLoading2({ operation: `delete_${recordId}`, loading: false })
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
const countRecords = async (filters) => {
|
|
970
|
+
if (!natsConnected || !orgId) {
|
|
971
|
+
throw new Error("Not connected or missing orgId");
|
|
972
|
+
}
|
|
973
|
+
try {
|
|
974
|
+
const response = await request(
|
|
975
|
+
EntityRecordCount,
|
|
976
|
+
{
|
|
977
|
+
orgId,
|
|
978
|
+
entityName,
|
|
979
|
+
filters: filters || {}
|
|
980
|
+
}
|
|
981
|
+
);
|
|
982
|
+
if (response instanceof Error) {
|
|
983
|
+
throw response;
|
|
984
|
+
}
|
|
985
|
+
if (!response.metadata?.success) {
|
|
986
|
+
throw new Error(response.metadata?.error || "Failed to count records");
|
|
987
|
+
}
|
|
988
|
+
return response.count || 0;
|
|
989
|
+
} catch (err) {
|
|
990
|
+
console.error("Error counting records:", err);
|
|
991
|
+
return 0;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
const getEntityRecordById = async (recordId) => {
|
|
995
|
+
if (!natsConnected || !orgId) {
|
|
996
|
+
throw new Error("Not connected or missing orgId");
|
|
997
|
+
}
|
|
998
|
+
try {
|
|
999
|
+
const response = await request(EntityRecordGet, { entityName, recordId, orgId }, {});
|
|
1000
|
+
if (response instanceof Error) {
|
|
1001
|
+
console.error("Error fetching record:", response.message);
|
|
1002
|
+
return null;
|
|
1003
|
+
}
|
|
1004
|
+
return response.record || null;
|
|
1005
|
+
} catch (error2) {
|
|
1006
|
+
console.error("Error in getEntityRecordById:", error2);
|
|
1007
|
+
return null;
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
const selectRecords = (ids) => {
|
|
1011
|
+
dispatch(setSelected({ entityName, ids }));
|
|
1012
|
+
};
|
|
1013
|
+
const clearSelection = () => {
|
|
1014
|
+
dispatch(setSelected({ entityName, ids: [] }));
|
|
1015
|
+
};
|
|
1016
|
+
const updateParams = (params) => {
|
|
1017
|
+
console.log("updating query params", params);
|
|
1018
|
+
dispatch(updateQueryParams({ entityName, params }));
|
|
1019
|
+
loadRecords(params);
|
|
1020
|
+
};
|
|
1021
|
+
const refresh = (0, import_react3.useCallback)(() => {
|
|
1022
|
+
loadRecords();
|
|
1023
|
+
}, [loadRecords]);
|
|
1024
|
+
(0, import_react3.useEffect)(() => {
|
|
1025
|
+
let mounted = true;
|
|
1026
|
+
if (autoLoad && natsConnected && orgId && mounted) {
|
|
1027
|
+
loadRecords();
|
|
1028
|
+
}
|
|
1029
|
+
return () => {
|
|
1030
|
+
mounted = false;
|
|
1031
|
+
};
|
|
1032
|
+
}, [autoLoad, natsConnected, orgId]);
|
|
1033
|
+
return {
|
|
1034
|
+
// State
|
|
1035
|
+
records: recordState.items,
|
|
1036
|
+
params: recordState.params,
|
|
1037
|
+
selected: recordState.selected,
|
|
1038
|
+
selectedRecord,
|
|
1039
|
+
isLoading,
|
|
1040
|
+
loadingStates,
|
|
1041
|
+
error,
|
|
1042
|
+
// Operations
|
|
1043
|
+
loadRecords,
|
|
1044
|
+
createRecord,
|
|
1045
|
+
updateRecord: updateRecordById,
|
|
1046
|
+
deleteRecord: deleteRecordById,
|
|
1047
|
+
loadRecord,
|
|
1048
|
+
countRecords,
|
|
1049
|
+
getEntityRecordById,
|
|
1050
|
+
// Selection
|
|
1051
|
+
selectRecords,
|
|
1052
|
+
clearSelection,
|
|
1053
|
+
// Query
|
|
1054
|
+
updateParams,
|
|
1055
|
+
refresh
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// hooks/use-debounce.ts
|
|
1060
|
+
var import_react4 = require("react");
|
|
1061
|
+
function useDebounce(callback, delay) {
|
|
1062
|
+
const timerRef = (0, import_react4.useRef)(null);
|
|
1063
|
+
return (0, import_react4.useCallback)((...args) => {
|
|
1064
|
+
if (timerRef.current) {
|
|
1065
|
+
clearTimeout(timerRef.current);
|
|
1066
|
+
}
|
|
1067
|
+
timerRef.current = setTimeout(() => {
|
|
1068
|
+
callback(...args);
|
|
1069
|
+
}, delay);
|
|
1070
|
+
}, [callback, delay]);
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// context/entity-definition-context.tsx
|
|
1074
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1075
|
+
var EntityDefinitionContext = (0, import_react5.createContext)(void 0);
|
|
1076
|
+
function EntityDefinitionProvider({
|
|
1077
|
+
children,
|
|
1078
|
+
orgId,
|
|
1079
|
+
entityName,
|
|
1080
|
+
options = {}
|
|
1081
|
+
}) {
|
|
1082
|
+
const hookValue = useEntityDefinition(orgId, entityName, options);
|
|
1083
|
+
const value = (0, import_react5.useMemo)(() => hookValue, [hookValue]);
|
|
1084
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EntityDefinitionContext.Provider, { value, children });
|
|
1085
|
+
}
|
|
1086
|
+
function useEntityDefinitionContext() {
|
|
1087
|
+
const context = (0, import_react5.useContext)(EntityDefinitionContext);
|
|
1088
|
+
if (!context) {
|
|
1089
|
+
throw new Error(
|
|
1090
|
+
"useEntityDefinitionContext must be used within an EntityDefinitionProvider"
|
|
1091
|
+
);
|
|
1092
|
+
}
|
|
1093
|
+
return context;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// context/entity-record-context.tsx
|
|
1097
|
+
var import_react6 = require("react");
|
|
1098
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1099
|
+
var EntityRecordContext = (0, import_react6.createContext)(void 0);
|
|
1100
|
+
function EntityRecordProvider({
|
|
1101
|
+
children,
|
|
1102
|
+
orgId,
|
|
1103
|
+
entityName,
|
|
1104
|
+
options = {}
|
|
1105
|
+
}) {
|
|
1106
|
+
const hookValue = useEntityRecord(orgId, entityName, options);
|
|
1107
|
+
const value = (0, import_react6.useMemo)(() => hookValue, [hookValue]);
|
|
1108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EntityRecordContext.Provider, { value, children });
|
|
1109
|
+
}
|
|
1110
|
+
function useEntityRecordContext() {
|
|
1111
|
+
const context = (0, import_react6.useContext)(EntityRecordContext);
|
|
1112
|
+
if (!context) {
|
|
1113
|
+
throw new Error(
|
|
1114
|
+
"useEntityRecordContext must be used within an EntityRecordProvider"
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
return context;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// consts/colors.ts
|
|
1121
|
+
var PREDEFINED_COLORS = [
|
|
1122
|
+
{ value: "#EF4444", name: "Red" },
|
|
1123
|
+
{ value: "#F97316", name: "Orange" },
|
|
1124
|
+
{ value: "#EAB308", name: "Yellow" },
|
|
1125
|
+
{ value: "#22C55E", name: "Green" },
|
|
1126
|
+
{ value: "#06B6D4", name: "Cyan" },
|
|
1127
|
+
{ value: "#3B82F6", name: "Blue" },
|
|
1128
|
+
{ value: "#6366F1", name: "Indigo" },
|
|
1129
|
+
{ value: "#A855F7", name: "Purple" }
|
|
1130
|
+
];
|
|
1131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1132
|
+
0 && (module.exports = {
|
|
1133
|
+
EntityDefinitionContext,
|
|
1134
|
+
EntityDefinitionCreate,
|
|
1135
|
+
EntityDefinitionCreated,
|
|
1136
|
+
EntityDefinitionDelete,
|
|
1137
|
+
EntityDefinitionDeleted,
|
|
1138
|
+
EntityDefinitionGet,
|
|
1139
|
+
EntityDefinitionGetServer,
|
|
1140
|
+
EntityDefinitionList,
|
|
1141
|
+
EntityDefinitionProvider,
|
|
1142
|
+
EntityDefinitionUpdate,
|
|
1143
|
+
EntityDefinitionUpdated,
|
|
1144
|
+
EntityFieldTypeBool,
|
|
1145
|
+
EntityFieldTypeCurrency,
|
|
1146
|
+
EntityFieldTypeDate,
|
|
1147
|
+
EntityFieldTypeDateTime,
|
|
1148
|
+
EntityFieldTypeDropdown,
|
|
1149
|
+
EntityFieldTypeEmail,
|
|
1150
|
+
EntityFieldTypeFile,
|
|
1151
|
+
EntityFieldTypeFloat,
|
|
1152
|
+
EntityFieldTypeImage,
|
|
1153
|
+
EntityFieldTypeInt,
|
|
1154
|
+
EntityFieldTypeJSON,
|
|
1155
|
+
EntityFieldTypeLookup,
|
|
1156
|
+
EntityFieldTypeMultiLookup,
|
|
1157
|
+
EntityFieldTypeMultiSelect,
|
|
1158
|
+
EntityFieldTypePhone,
|
|
1159
|
+
EntityFieldTypeString,
|
|
1160
|
+
EntityFieldTypeStringMultiline,
|
|
1161
|
+
EntityFieldTypeText,
|
|
1162
|
+
EntityFieldTypeURL,
|
|
1163
|
+
EntityFieldTypes,
|
|
1164
|
+
EntityFilterOperators,
|
|
1165
|
+
EntityOrgSchemaCreate,
|
|
1166
|
+
EntityOrgSchemaDrop,
|
|
1167
|
+
EntityRecordContext,
|
|
1168
|
+
EntityRecordCount,
|
|
1169
|
+
EntityRecordCreate,
|
|
1170
|
+
EntityRecordCreated,
|
|
1171
|
+
EntityRecordDelete,
|
|
1172
|
+
EntityRecordDeleted,
|
|
1173
|
+
EntityRecordGet,
|
|
1174
|
+
EntityRecordProvider,
|
|
1175
|
+
EntityRecordQuery,
|
|
1176
|
+
EntityRecordUpdate,
|
|
1177
|
+
EntityRecordUpdated,
|
|
1178
|
+
EntityRecordsBulkCreate,
|
|
1179
|
+
EntityRecordsBulkCreated,
|
|
1180
|
+
EntityRecordsBulkDelete,
|
|
1181
|
+
EntityRecordsBulkDeleted,
|
|
1182
|
+
EntityRecordsBulkUpdate,
|
|
1183
|
+
EntityRecordsBulkUpdated,
|
|
1184
|
+
EntityViewCreate,
|
|
1185
|
+
EntityViewCreated,
|
|
1186
|
+
EntityViewDelete,
|
|
1187
|
+
EntityViewDeleted,
|
|
1188
|
+
EntityViewList,
|
|
1189
|
+
EntityViewUpdate,
|
|
1190
|
+
EntityViewUpdated,
|
|
1191
|
+
OperatorBetween,
|
|
1192
|
+
OperatorContains,
|
|
1193
|
+
OperatorEmpty,
|
|
1194
|
+
OperatorEndsWith,
|
|
1195
|
+
OperatorEq,
|
|
1196
|
+
OperatorExists,
|
|
1197
|
+
OperatorGt,
|
|
1198
|
+
OperatorGte,
|
|
1199
|
+
OperatorIn,
|
|
1200
|
+
OperatorLt,
|
|
1201
|
+
OperatorLte,
|
|
1202
|
+
OperatorNe,
|
|
1203
|
+
OperatorNin,
|
|
1204
|
+
OperatorStartsWith,
|
|
1205
|
+
PREDEFINED_COLORS,
|
|
1206
|
+
RecordChangeActionCreated,
|
|
1207
|
+
RecordChangeActionDeleted,
|
|
1208
|
+
RecordChangeActionUpdated,
|
|
1209
|
+
entityDefinitionReducer,
|
|
1210
|
+
entityRecordReducer,
|
|
1211
|
+
useDebounce,
|
|
1212
|
+
useEntityDefinition,
|
|
1213
|
+
useEntityDefinitionContext,
|
|
1214
|
+
useEntityDefinitionDetails,
|
|
1215
|
+
useEntityRecord,
|
|
1216
|
+
useEntityRecordContext
|
|
1217
|
+
});
|
|
1218
|
+
//# sourceMappingURL=index.js.map
|