@elqnt/entity 1.0.7 → 2.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 +3 -91
- package/dist/index.d.ts +3 -91
- package/dist/index.js +2 -715
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -714
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.mjs
CHANGED
|
@@ -73,14 +73,6 @@ import {
|
|
|
73
73
|
RecordChangeActionUpdated
|
|
74
74
|
} from "./chunk-LIACJMHV.mjs";
|
|
75
75
|
|
|
76
|
-
// context/entity-definition-context.tsx
|
|
77
|
-
import { createContext, useContext, useMemo } from "react";
|
|
78
|
-
|
|
79
|
-
// hooks/use-entity-definition.ts
|
|
80
|
-
import { useCallback, useEffect } from "react";
|
|
81
|
-
import { useDispatch, useSelector } from "react-redux";
|
|
82
|
-
import { useNatsContext } from "@elqnt/nats";
|
|
83
|
-
|
|
84
76
|
// store/entity-definition-slice.ts
|
|
85
77
|
import { createSlice } from "@reduxjs/toolkit";
|
|
86
78
|
var initialState = {
|
|
@@ -187,364 +179,6 @@ var {
|
|
|
187
179
|
} = entityDefinitionSlice.actions;
|
|
188
180
|
var entityDefinitionReducer = entityDefinitionSlice.reducer;
|
|
189
181
|
|
|
190
|
-
// hooks/use-entity-definition.ts
|
|
191
|
-
function useEntityDefinition(orgId, entityName, options = {}) {
|
|
192
|
-
const { autoLoad, module } = options;
|
|
193
|
-
const { natsConnected, request } = useNatsContext();
|
|
194
|
-
const dispatch = useDispatch();
|
|
195
|
-
const definitions = useSelector(
|
|
196
|
-
(state) => state.entityDefinition.definitions
|
|
197
|
-
);
|
|
198
|
-
const selectedDefinition = useSelector(
|
|
199
|
-
(state) => state.entityDefinition.selectedDefinition
|
|
200
|
-
);
|
|
201
|
-
const views = useSelector(
|
|
202
|
-
(state) => state.entityDefinition.views
|
|
203
|
-
);
|
|
204
|
-
const selectedView = useSelector(
|
|
205
|
-
(state) => state.entityDefinition.selectedView
|
|
206
|
-
);
|
|
207
|
-
const isLoading = useSelector(
|
|
208
|
-
(state) => state.entityDefinition.isLoading
|
|
209
|
-
);
|
|
210
|
-
const loadingStates = useSelector(
|
|
211
|
-
(state) => state.entityDefinition.loadingStates
|
|
212
|
-
);
|
|
213
|
-
const error = useSelector(
|
|
214
|
-
(state) => state.entityDefinition.error
|
|
215
|
-
);
|
|
216
|
-
const createOrgSchema = useCallback(
|
|
217
|
-
async (targetOrgId) => {
|
|
218
|
-
if (!natsConnected) {
|
|
219
|
-
throw new Error("Not connected to NATS");
|
|
220
|
-
}
|
|
221
|
-
dispatch(setOperationLoading({ operation: "createOrgSchema", loading: true }));
|
|
222
|
-
try {
|
|
223
|
-
const response = await request(EntityOrgSchemaCreate, { orgId: targetOrgId });
|
|
224
|
-
if (response instanceof Error) {
|
|
225
|
-
throw response;
|
|
226
|
-
}
|
|
227
|
-
return response;
|
|
228
|
-
} finally {
|
|
229
|
-
dispatch(setOperationLoading({ operation: "createOrgSchema", loading: false }));
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
[natsConnected, dispatch, request]
|
|
233
|
-
);
|
|
234
|
-
const dropOrgSchema = useCallback(
|
|
235
|
-
async (targetOrgId) => {
|
|
236
|
-
if (!natsConnected) {
|
|
237
|
-
throw new Error("Not connected to NATS");
|
|
238
|
-
}
|
|
239
|
-
dispatch(setOperationLoading({ operation: "dropOrgSchema", loading: true }));
|
|
240
|
-
try {
|
|
241
|
-
const response = await request(EntityOrgSchemaDrop, { orgId: targetOrgId });
|
|
242
|
-
if (response instanceof Error) {
|
|
243
|
-
throw response;
|
|
244
|
-
}
|
|
245
|
-
return response;
|
|
246
|
-
} finally {
|
|
247
|
-
dispatch(setOperationLoading({ operation: "dropOrgSchema", loading: false }));
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
[natsConnected, dispatch, request]
|
|
251
|
-
);
|
|
252
|
-
const loadDefinitions = useCallback(async () => {
|
|
253
|
-
if (!natsConnected || !orgId) return;
|
|
254
|
-
const loadingKey = "loadDefinitions";
|
|
255
|
-
if (loadingStates[loadingKey]) return;
|
|
256
|
-
dispatch(setOperationLoading({ operation: loadingKey, loading: true }));
|
|
257
|
-
try {
|
|
258
|
-
const response = await request(EntityDefinitionList, { orgId, module });
|
|
259
|
-
if (response instanceof Error) {
|
|
260
|
-
dispatch(setError(response.message));
|
|
261
|
-
} else {
|
|
262
|
-
dispatch(setDefinitions(response?.definitions ?? []));
|
|
263
|
-
}
|
|
264
|
-
} catch (err) {
|
|
265
|
-
dispatch(setError(err instanceof Error ? err.message : "Unknown error"));
|
|
266
|
-
} finally {
|
|
267
|
-
dispatch(setOperationLoading({ operation: loadingKey, loading: false }));
|
|
268
|
-
}
|
|
269
|
-
}, [natsConnected, orgId, options.module, dispatch, request]);
|
|
270
|
-
useEffect(() => {
|
|
271
|
-
let mounted = true;
|
|
272
|
-
if (autoLoad && natsConnected && orgId && mounted) {
|
|
273
|
-
loadDefinitions();
|
|
274
|
-
}
|
|
275
|
-
return () => {
|
|
276
|
-
mounted = false;
|
|
277
|
-
};
|
|
278
|
-
}, [autoLoad, natsConnected, orgId]);
|
|
279
|
-
const loadDefinition = useCallback(
|
|
280
|
-
async (name) => {
|
|
281
|
-
if (!natsConnected || !orgId) return;
|
|
282
|
-
dispatch(
|
|
283
|
-
setOperationLoading({ operation: `load_${name}`, loading: true })
|
|
284
|
-
);
|
|
285
|
-
try {
|
|
286
|
-
const response = await request(EntityDefinitionGet, { entityName: name, orgId }, {});
|
|
287
|
-
if (response instanceof Error) {
|
|
288
|
-
dispatch(setError(response.message));
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
dispatch(setSelectedDefinition(response.definition));
|
|
292
|
-
} finally {
|
|
293
|
-
dispatch(
|
|
294
|
-
setOperationLoading({ operation: `load_${name}`, loading: false })
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
[natsConnected, orgId, dispatch, request]
|
|
299
|
-
);
|
|
300
|
-
useEffect(() => {
|
|
301
|
-
if (natsConnected && orgId && entityName) {
|
|
302
|
-
loadDefinition(entityName);
|
|
303
|
-
}
|
|
304
|
-
}, [natsConnected, orgId, entityName, loadDefinition]);
|
|
305
|
-
const createDefinition = async (definition) => {
|
|
306
|
-
if (!natsConnected || !orgId) {
|
|
307
|
-
throw new Error("Not connected or missing orgId");
|
|
308
|
-
}
|
|
309
|
-
dispatch(setOperationLoading({ operation: "create", loading: true }));
|
|
310
|
-
try {
|
|
311
|
-
const response = await request(EntityDefinitionCreate, { definition, orgId }, {});
|
|
312
|
-
if (response instanceof Error) {
|
|
313
|
-
console.error("createDefinition error", response);
|
|
314
|
-
throw response;
|
|
315
|
-
}
|
|
316
|
-
if (response.metadata.success) {
|
|
317
|
-
dispatch(addDefinition(response.definition));
|
|
318
|
-
}
|
|
319
|
-
return response;
|
|
320
|
-
} finally {
|
|
321
|
-
dispatch(setOperationLoading({ operation: "create", loading: false }));
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
const updateDefinitionById = async (name, definition) => {
|
|
325
|
-
if (!natsConnected || !orgId) {
|
|
326
|
-
throw new Error("Not connected or missing orgId");
|
|
327
|
-
}
|
|
328
|
-
dispatch(
|
|
329
|
-
setOperationLoading({ operation: `update_${name}`, loading: true })
|
|
330
|
-
);
|
|
331
|
-
try {
|
|
332
|
-
const response = await request(
|
|
333
|
-
EntityDefinitionUpdate,
|
|
334
|
-
{
|
|
335
|
-
entityName: name,
|
|
336
|
-
definition,
|
|
337
|
-
orgId
|
|
338
|
-
},
|
|
339
|
-
{}
|
|
340
|
-
);
|
|
341
|
-
if (response instanceof Error) {
|
|
342
|
-
throw response;
|
|
343
|
-
}
|
|
344
|
-
if (response.metadata.success) {
|
|
345
|
-
dispatch(updateDefinition(response.definition));
|
|
346
|
-
}
|
|
347
|
-
return response;
|
|
348
|
-
} finally {
|
|
349
|
-
dispatch(
|
|
350
|
-
setOperationLoading({ operation: `update_${name}`, loading: false })
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
const deleteDefinition = async (name) => {
|
|
355
|
-
if (!natsConnected || !orgId) {
|
|
356
|
-
throw new Error("Not connected or missing orgId");
|
|
357
|
-
}
|
|
358
|
-
dispatch(
|
|
359
|
-
setOperationLoading({ operation: `delete_${name}`, loading: true })
|
|
360
|
-
);
|
|
361
|
-
try {
|
|
362
|
-
const response = await request(EntityDefinitionDelete, { entityName: name, orgId }, {});
|
|
363
|
-
if (response instanceof Error) {
|
|
364
|
-
throw response;
|
|
365
|
-
}
|
|
366
|
-
dispatch(removeDefinition(name));
|
|
367
|
-
return response;
|
|
368
|
-
} finally {
|
|
369
|
-
dispatch(
|
|
370
|
-
setOperationLoading({ operation: `delete_${name}`, loading: false })
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
const loadViews = useCallback(
|
|
375
|
-
async (entityName2) => {
|
|
376
|
-
if (!natsConnected || !orgId) return;
|
|
377
|
-
const loadingKey = `loadViews_${entityName2}`;
|
|
378
|
-
if (loadingStates[loadingKey]) return;
|
|
379
|
-
dispatch(setOperationLoading({ operation: loadingKey, loading: true }));
|
|
380
|
-
try {
|
|
381
|
-
const response = await request(
|
|
382
|
-
EntityViewList,
|
|
383
|
-
{ entityName: entityName2, orgId },
|
|
384
|
-
{}
|
|
385
|
-
);
|
|
386
|
-
console.log("loadViews response", response);
|
|
387
|
-
if (response instanceof Error) {
|
|
388
|
-
dispatch(setError(response.message));
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
dispatch(setViews({ entityName: entityName2, views: response.views }));
|
|
392
|
-
} catch (err) {
|
|
393
|
-
dispatch(
|
|
394
|
-
setError(err instanceof Error ? err.message : "Unknown error")
|
|
395
|
-
);
|
|
396
|
-
} finally {
|
|
397
|
-
dispatch(
|
|
398
|
-
setOperationLoading({ operation: loadingKey, loading: false })
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
[natsConnected, orgId, loadingStates, dispatch, request]
|
|
403
|
-
);
|
|
404
|
-
const createView = async (entityName2, view) => {
|
|
405
|
-
if (!natsConnected || !orgId) {
|
|
406
|
-
throw new Error("Not connected or missing orgId");
|
|
407
|
-
}
|
|
408
|
-
dispatch(setOperationLoading({ operation: "create_view", loading: true }));
|
|
409
|
-
try {
|
|
410
|
-
const response = await request(
|
|
411
|
-
EntityViewCreate,
|
|
412
|
-
{ entityName: entityName2, view, orgId },
|
|
413
|
-
{}
|
|
414
|
-
);
|
|
415
|
-
if (response instanceof Error) {
|
|
416
|
-
throw response;
|
|
417
|
-
}
|
|
418
|
-
dispatch(addView({ entityName: entityName2, view: response.view }));
|
|
419
|
-
return response.view;
|
|
420
|
-
} finally {
|
|
421
|
-
dispatch(
|
|
422
|
-
setOperationLoading({ operation: "create_view", loading: false })
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
const updateViewById = async (entityName2, view) => {
|
|
427
|
-
if (!natsConnected || !orgId || !view.id) {
|
|
428
|
-
throw new Error("Not connected, missing orgId, or invalid view");
|
|
429
|
-
}
|
|
430
|
-
dispatch(
|
|
431
|
-
setOperationLoading({
|
|
432
|
-
operation: `update_view_${view.id}`,
|
|
433
|
-
loading: true
|
|
434
|
-
})
|
|
435
|
-
);
|
|
436
|
-
try {
|
|
437
|
-
const response = await request(
|
|
438
|
-
EntityViewUpdate,
|
|
439
|
-
{ view, orgId },
|
|
440
|
-
{}
|
|
441
|
-
);
|
|
442
|
-
if (response instanceof Error) {
|
|
443
|
-
throw response;
|
|
444
|
-
}
|
|
445
|
-
dispatch(updateView({ entityName: entityName2, view: response.view }));
|
|
446
|
-
return response.view;
|
|
447
|
-
} finally {
|
|
448
|
-
dispatch(
|
|
449
|
-
setOperationLoading({
|
|
450
|
-
operation: `update_view_${view.id}`,
|
|
451
|
-
loading: false
|
|
452
|
-
})
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
const deleteView = async (entityName2, viewId) => {
|
|
457
|
-
if (!natsConnected || !orgId) {
|
|
458
|
-
throw new Error("Not connected or missing orgId");
|
|
459
|
-
}
|
|
460
|
-
dispatch(
|
|
461
|
-
setOperationLoading({ operation: `delete_view_${viewId}`, loading: true })
|
|
462
|
-
);
|
|
463
|
-
try {
|
|
464
|
-
const response = await request(
|
|
465
|
-
EntityViewDelete,
|
|
466
|
-
{ viewId, orgId },
|
|
467
|
-
{}
|
|
468
|
-
);
|
|
469
|
-
if (response instanceof Error) {
|
|
470
|
-
throw response;
|
|
471
|
-
}
|
|
472
|
-
dispatch(removeView({ entityName: entityName2, viewId }));
|
|
473
|
-
return response;
|
|
474
|
-
} finally {
|
|
475
|
-
dispatch(
|
|
476
|
-
setOperationLoading({
|
|
477
|
-
operation: `delete_view_${viewId}`,
|
|
478
|
-
loading: false
|
|
479
|
-
})
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
const refresh = useCallback(() => {
|
|
484
|
-
if (!natsConnected || !orgId) return;
|
|
485
|
-
if (entityName) {
|
|
486
|
-
loadDefinition(entityName);
|
|
487
|
-
} else {
|
|
488
|
-
dispatch(setLoading(true));
|
|
489
|
-
loadDefinitions().finally(() => dispatch(setLoading(false)));
|
|
490
|
-
}
|
|
491
|
-
}, [natsConnected, orgId, entityName, loadDefinition, dispatch]);
|
|
492
|
-
return {
|
|
493
|
-
// State
|
|
494
|
-
definitions,
|
|
495
|
-
selectedDefinition,
|
|
496
|
-
views,
|
|
497
|
-
selectedView,
|
|
498
|
-
isLoading,
|
|
499
|
-
loadingStates,
|
|
500
|
-
error,
|
|
501
|
-
// Organization operations
|
|
502
|
-
createOrgSchema,
|
|
503
|
-
dropOrgSchema,
|
|
504
|
-
// Definition operations
|
|
505
|
-
loadDefinitions,
|
|
506
|
-
loadDefinition,
|
|
507
|
-
createDefinition,
|
|
508
|
-
updateDefinition: updateDefinitionById,
|
|
509
|
-
deleteDefinition,
|
|
510
|
-
// View operations
|
|
511
|
-
loadViews,
|
|
512
|
-
createView,
|
|
513
|
-
updateView: updateViewById,
|
|
514
|
-
deleteView,
|
|
515
|
-
// Utilities
|
|
516
|
-
refresh
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// hooks/use-entity-definition-details.ts
|
|
521
|
-
import { useCallback as useCallback2, useEffect as useEffect2 } from "react";
|
|
522
|
-
function useEntityDefinitionDetails(entityName) {
|
|
523
|
-
const context = useEntityDefinitionContext();
|
|
524
|
-
const definition = context.definitions[entityName];
|
|
525
|
-
const loadDefinitionDetails = useCallback2(async () => {
|
|
526
|
-
return context.loadDefinition(entityName);
|
|
527
|
-
}, [context, entityName]);
|
|
528
|
-
useEffect2(() => {
|
|
529
|
-
if (entityName && !definition) {
|
|
530
|
-
loadDefinitionDetails();
|
|
531
|
-
}
|
|
532
|
-
}, [definition, entityName, loadDefinitionDetails]);
|
|
533
|
-
return {
|
|
534
|
-
definition,
|
|
535
|
-
isLoading: context.loadingStates[`load_${entityName}`],
|
|
536
|
-
error: context.error,
|
|
537
|
-
updateDefinition: (updatedDef) => context.updateDefinition(entityName, updatedDef),
|
|
538
|
-
deleteDefinition: () => context.deleteDefinition(entityName),
|
|
539
|
-
refresh: loadDefinitionDetails
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// hooks/use-entity-record.ts
|
|
544
|
-
import { useCallback as useCallback3, useEffect as useEffect3 } from "react";
|
|
545
|
-
import { useDispatch as useDispatch2, useSelector as useSelector2 } from "react-redux";
|
|
546
|
-
import { useNatsContext as useNatsContext2 } from "@elqnt/nats";
|
|
547
|
-
|
|
548
182
|
// store/entity-record-slice.ts
|
|
549
183
|
import { createSlice as createSlice2 } from "@reduxjs/toolkit";
|
|
550
184
|
var initialState2 = {
|
|
@@ -638,343 +272,6 @@ var {
|
|
|
638
272
|
} = entityRecordSlice.actions;
|
|
639
273
|
var entityRecordReducer = entityRecordSlice.reducer;
|
|
640
274
|
|
|
641
|
-
// hooks/use-entity-record.ts
|
|
642
|
-
var defaultQuery = {
|
|
643
|
-
filters: {},
|
|
644
|
-
page: 1,
|
|
645
|
-
pageSize: 25,
|
|
646
|
-
sortBy: "metadata.createdAt",
|
|
647
|
-
sortOrder: -1
|
|
648
|
-
};
|
|
649
|
-
function useEntityRecord(orgId, entityName, options = {}) {
|
|
650
|
-
const { autoLoad = true } = options;
|
|
651
|
-
const { natsConnected, request } = useNatsContext2();
|
|
652
|
-
const dispatch = useDispatch2();
|
|
653
|
-
const recordState = useSelector2(
|
|
654
|
-
(state) => state.entityRecord.records[entityName] || {
|
|
655
|
-
items: {},
|
|
656
|
-
params: defaultQuery,
|
|
657
|
-
meta: {
|
|
658
|
-
items: [],
|
|
659
|
-
totalCount: 0,
|
|
660
|
-
currentPage: 1,
|
|
661
|
-
pageSize: 25,
|
|
662
|
-
totalPages: 0
|
|
663
|
-
},
|
|
664
|
-
selected: []
|
|
665
|
-
}
|
|
666
|
-
);
|
|
667
|
-
const selectedRecord = useSelector2(
|
|
668
|
-
(state) => state.entityRecord.selectedRecord
|
|
669
|
-
);
|
|
670
|
-
const isLoading = useSelector2(
|
|
671
|
-
(state) => state.entityRecord.isLoading
|
|
672
|
-
);
|
|
673
|
-
const loadingStates = useSelector2(
|
|
674
|
-
(state) => state.entityRecord.loadingStates
|
|
675
|
-
);
|
|
676
|
-
const error = useSelector2(
|
|
677
|
-
(state) => state.entityRecord.error
|
|
678
|
-
);
|
|
679
|
-
const loadRecords = useCallback3(
|
|
680
|
-
async (params) => {
|
|
681
|
-
if (!natsConnected || !orgId) return;
|
|
682
|
-
const loadingKey = `load_${entityName}`;
|
|
683
|
-
if (loadingStates[loadingKey]) return;
|
|
684
|
-
dispatch(setOperationLoading2({ operation: loadingKey, loading: true }));
|
|
685
|
-
try {
|
|
686
|
-
const queryParams = { ...recordState.params, ...params };
|
|
687
|
-
const response = await request(
|
|
688
|
-
EntityRecordQuery,
|
|
689
|
-
{
|
|
690
|
-
orgId,
|
|
691
|
-
entityName,
|
|
692
|
-
query: queryParams
|
|
693
|
-
}
|
|
694
|
-
);
|
|
695
|
-
if (response instanceof Error) {
|
|
696
|
-
dispatch(setError2(response.message));
|
|
697
|
-
} else if (response.records) {
|
|
698
|
-
dispatch(
|
|
699
|
-
setRecords({
|
|
700
|
-
entityName,
|
|
701
|
-
records: response.records,
|
|
702
|
-
params: queryParams
|
|
703
|
-
})
|
|
704
|
-
);
|
|
705
|
-
}
|
|
706
|
-
} catch (err) {
|
|
707
|
-
dispatch(
|
|
708
|
-
setError2(err instanceof Error ? err.message : "Unknown error")
|
|
709
|
-
);
|
|
710
|
-
} finally {
|
|
711
|
-
dispatch(
|
|
712
|
-
setOperationLoading2({ operation: loadingKey, loading: false })
|
|
713
|
-
);
|
|
714
|
-
}
|
|
715
|
-
},
|
|
716
|
-
[natsConnected, orgId, entityName, recordState.params, dispatch, request]
|
|
717
|
-
);
|
|
718
|
-
const loadRecord = useCallback3(
|
|
719
|
-
async (recordId) => {
|
|
720
|
-
if (!natsConnected || !orgId) return;
|
|
721
|
-
const loadingKey = `load_${recordId}`;
|
|
722
|
-
if (loadingStates[loadingKey]) return;
|
|
723
|
-
dispatch(setOperationLoading2({ operation: loadingKey, loading: true }));
|
|
724
|
-
try {
|
|
725
|
-
const response = await request(EntityRecordGet, { entityName, recordId, orgId }, {});
|
|
726
|
-
if (response instanceof Error) {
|
|
727
|
-
dispatch(setError2(response.message));
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
dispatch(setSelectedRecord({ record: response.record }));
|
|
731
|
-
} finally {
|
|
732
|
-
dispatch(
|
|
733
|
-
setOperationLoading2({ operation: loadingKey, loading: false })
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
},
|
|
737
|
-
[natsConnected, orgId, entityName, recordState.params, dispatch, request]
|
|
738
|
-
);
|
|
739
|
-
const createRecord = async (record) => {
|
|
740
|
-
if (!natsConnected || !orgId) {
|
|
741
|
-
throw new Error("Not connected or missing orgId");
|
|
742
|
-
}
|
|
743
|
-
dispatch(
|
|
744
|
-
setOperationLoading2({ operation: "create_record", loading: true })
|
|
745
|
-
);
|
|
746
|
-
try {
|
|
747
|
-
const response = await request(
|
|
748
|
-
EntityRecordCreate,
|
|
749
|
-
{
|
|
750
|
-
orgId,
|
|
751
|
-
entityName,
|
|
752
|
-
record
|
|
753
|
-
}
|
|
754
|
-
);
|
|
755
|
-
if (response instanceof Error) {
|
|
756
|
-
throw response;
|
|
757
|
-
}
|
|
758
|
-
if (response.metadata.success) {
|
|
759
|
-
dispatch(addRecord({ entityName, record: response.record }));
|
|
760
|
-
}
|
|
761
|
-
loadRecords();
|
|
762
|
-
return response;
|
|
763
|
-
} finally {
|
|
764
|
-
dispatch(
|
|
765
|
-
setOperationLoading2({ operation: "create_record", loading: false })
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
const updateRecordById = async (record) => {
|
|
770
|
-
if (!natsConnected || !orgId) {
|
|
771
|
-
throw new Error("Not connected or missing orgId");
|
|
772
|
-
}
|
|
773
|
-
dispatch(
|
|
774
|
-
setOperationLoading2({ operation: `update_${record.id}`, loading: true })
|
|
775
|
-
);
|
|
776
|
-
try {
|
|
777
|
-
const response = await request(
|
|
778
|
-
EntityRecordUpdate,
|
|
779
|
-
{
|
|
780
|
-
orgId,
|
|
781
|
-
entityName,
|
|
782
|
-
record,
|
|
783
|
-
recordId: record.id
|
|
784
|
-
}
|
|
785
|
-
);
|
|
786
|
-
if (response instanceof Error) {
|
|
787
|
-
throw response;
|
|
788
|
-
}
|
|
789
|
-
dispatch(updateRecord({ entityName, record: response.record }));
|
|
790
|
-
return response;
|
|
791
|
-
} finally {
|
|
792
|
-
dispatch(
|
|
793
|
-
setOperationLoading2({
|
|
794
|
-
operation: `update_${record.id}`,
|
|
795
|
-
loading: false
|
|
796
|
-
})
|
|
797
|
-
);
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
const deleteRecordById = async (recordId) => {
|
|
801
|
-
if (!natsConnected || !orgId) {
|
|
802
|
-
throw new Error("Not connected or missing orgId");
|
|
803
|
-
}
|
|
804
|
-
dispatch(
|
|
805
|
-
setOperationLoading2({ operation: `delete_${recordId}`, loading: true })
|
|
806
|
-
);
|
|
807
|
-
try {
|
|
808
|
-
const response = await request(
|
|
809
|
-
EntityRecordDelete,
|
|
810
|
-
{
|
|
811
|
-
orgId,
|
|
812
|
-
entityName,
|
|
813
|
-
recordId
|
|
814
|
-
}
|
|
815
|
-
);
|
|
816
|
-
if (response instanceof Error) {
|
|
817
|
-
throw response;
|
|
818
|
-
}
|
|
819
|
-
dispatch(removeRecord({ entityName, recordId }));
|
|
820
|
-
return response;
|
|
821
|
-
} finally {
|
|
822
|
-
dispatch(
|
|
823
|
-
setOperationLoading2({ operation: `delete_${recordId}`, loading: false })
|
|
824
|
-
);
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
const countRecords = async (filters) => {
|
|
828
|
-
if (!natsConnected || !orgId) {
|
|
829
|
-
throw new Error("Not connected or missing orgId");
|
|
830
|
-
}
|
|
831
|
-
try {
|
|
832
|
-
const response = await request(
|
|
833
|
-
EntityRecordCount,
|
|
834
|
-
{
|
|
835
|
-
orgId,
|
|
836
|
-
entityName,
|
|
837
|
-
filters: filters || {}
|
|
838
|
-
}
|
|
839
|
-
);
|
|
840
|
-
if (response instanceof Error) {
|
|
841
|
-
throw response;
|
|
842
|
-
}
|
|
843
|
-
if (!response.metadata?.success) {
|
|
844
|
-
throw new Error(response.metadata?.error || "Failed to count records");
|
|
845
|
-
}
|
|
846
|
-
return response.count || 0;
|
|
847
|
-
} catch (err) {
|
|
848
|
-
console.error("Error counting records:", err);
|
|
849
|
-
return 0;
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
const getEntityRecordById = async (recordId) => {
|
|
853
|
-
if (!natsConnected || !orgId) {
|
|
854
|
-
throw new Error("Not connected or missing orgId");
|
|
855
|
-
}
|
|
856
|
-
try {
|
|
857
|
-
const response = await request(EntityRecordGet, { entityName, recordId, orgId }, {});
|
|
858
|
-
if (response instanceof Error) {
|
|
859
|
-
console.error("Error fetching record:", response.message);
|
|
860
|
-
return null;
|
|
861
|
-
}
|
|
862
|
-
return response.record || null;
|
|
863
|
-
} catch (error2) {
|
|
864
|
-
console.error("Error in getEntityRecordById:", error2);
|
|
865
|
-
return null;
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
const selectRecords = (ids) => {
|
|
869
|
-
dispatch(setSelected({ entityName, ids }));
|
|
870
|
-
};
|
|
871
|
-
const clearSelection = () => {
|
|
872
|
-
dispatch(setSelected({ entityName, ids: [] }));
|
|
873
|
-
};
|
|
874
|
-
const updateParams = (params) => {
|
|
875
|
-
console.log("updating query params", params);
|
|
876
|
-
dispatch(updateQueryParams({ entityName, params }));
|
|
877
|
-
loadRecords(params);
|
|
878
|
-
};
|
|
879
|
-
const refresh = useCallback3(() => {
|
|
880
|
-
loadRecords();
|
|
881
|
-
}, [loadRecords]);
|
|
882
|
-
useEffect3(() => {
|
|
883
|
-
let mounted = true;
|
|
884
|
-
if (autoLoad && natsConnected && orgId && mounted) {
|
|
885
|
-
loadRecords();
|
|
886
|
-
}
|
|
887
|
-
return () => {
|
|
888
|
-
mounted = false;
|
|
889
|
-
};
|
|
890
|
-
}, [autoLoad, natsConnected, orgId]);
|
|
891
|
-
return {
|
|
892
|
-
// State
|
|
893
|
-
records: recordState.items,
|
|
894
|
-
params: recordState.params,
|
|
895
|
-
selected: recordState.selected,
|
|
896
|
-
selectedRecord,
|
|
897
|
-
isLoading,
|
|
898
|
-
loadingStates,
|
|
899
|
-
error,
|
|
900
|
-
// Operations
|
|
901
|
-
loadRecords,
|
|
902
|
-
createRecord,
|
|
903
|
-
updateRecord: updateRecordById,
|
|
904
|
-
deleteRecord: deleteRecordById,
|
|
905
|
-
loadRecord,
|
|
906
|
-
countRecords,
|
|
907
|
-
getEntityRecordById,
|
|
908
|
-
// Selection
|
|
909
|
-
selectRecords,
|
|
910
|
-
clearSelection,
|
|
911
|
-
// Query
|
|
912
|
-
updateParams,
|
|
913
|
-
refresh
|
|
914
|
-
};
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
// hooks/use-debounce.ts
|
|
918
|
-
import { useCallback as useCallback4, useRef } from "react";
|
|
919
|
-
function useDebounce(callback, delay) {
|
|
920
|
-
const timerRef = useRef(null);
|
|
921
|
-
return useCallback4((...args) => {
|
|
922
|
-
if (timerRef.current) {
|
|
923
|
-
clearTimeout(timerRef.current);
|
|
924
|
-
}
|
|
925
|
-
timerRef.current = setTimeout(() => {
|
|
926
|
-
callback(...args);
|
|
927
|
-
}, delay);
|
|
928
|
-
}, [callback, delay]);
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
// context/entity-definition-context.tsx
|
|
932
|
-
import { jsx } from "react/jsx-runtime";
|
|
933
|
-
var EntityDefinitionContext = createContext(void 0);
|
|
934
|
-
function EntityDefinitionProvider({
|
|
935
|
-
children,
|
|
936
|
-
orgId,
|
|
937
|
-
entityName,
|
|
938
|
-
options = {}
|
|
939
|
-
}) {
|
|
940
|
-
const hookValue = useEntityDefinition(orgId, entityName, options);
|
|
941
|
-
const value = useMemo(() => hookValue, [hookValue]);
|
|
942
|
-
return /* @__PURE__ */ jsx(EntityDefinitionContext.Provider, { value, children });
|
|
943
|
-
}
|
|
944
|
-
function useEntityDefinitionContext() {
|
|
945
|
-
const context = useContext(EntityDefinitionContext);
|
|
946
|
-
if (!context) {
|
|
947
|
-
throw new Error(
|
|
948
|
-
"useEntityDefinitionContext must be used within an EntityDefinitionProvider"
|
|
949
|
-
);
|
|
950
|
-
}
|
|
951
|
-
return context;
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
// context/entity-record-context.tsx
|
|
955
|
-
import { createContext as createContext2, useContext as useContext2, useMemo as useMemo2 } from "react";
|
|
956
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
957
|
-
var EntityRecordContext = createContext2(void 0);
|
|
958
|
-
function EntityRecordProvider({
|
|
959
|
-
children,
|
|
960
|
-
orgId,
|
|
961
|
-
entityName,
|
|
962
|
-
options = {}
|
|
963
|
-
}) {
|
|
964
|
-
const hookValue = useEntityRecord(orgId, entityName, options);
|
|
965
|
-
const value = useMemo2(() => hookValue, [hookValue]);
|
|
966
|
-
return /* @__PURE__ */ jsx2(EntityRecordContext.Provider, { value, children });
|
|
967
|
-
}
|
|
968
|
-
function useEntityRecordContext() {
|
|
969
|
-
const context = useContext2(EntityRecordContext);
|
|
970
|
-
if (!context) {
|
|
971
|
-
throw new Error(
|
|
972
|
-
"useEntityRecordContext must be used within an EntityRecordProvider"
|
|
973
|
-
);
|
|
974
|
-
}
|
|
975
|
-
return context;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
275
|
// consts/colors.ts
|
|
979
276
|
var PREDEFINED_COLORS = [
|
|
980
277
|
{ value: "#EF4444", name: "Red" },
|
|
@@ -987,7 +284,6 @@ var PREDEFINED_COLORS = [
|
|
|
987
284
|
{ value: "#A855F7", name: "Purple" }
|
|
988
285
|
];
|
|
989
286
|
export {
|
|
990
|
-
EntityDefinitionContext,
|
|
991
287
|
EntityDefinitionCreate,
|
|
992
288
|
EntityDefinitionCreated,
|
|
993
289
|
EntityDefinitionDelete,
|
|
@@ -995,7 +291,6 @@ export {
|
|
|
995
291
|
EntityDefinitionGet,
|
|
996
292
|
EntityDefinitionGetServer,
|
|
997
293
|
EntityDefinitionList,
|
|
998
|
-
EntityDefinitionProvider,
|
|
999
294
|
EntityDefinitionUpdate,
|
|
1000
295
|
EntityDefinitionUpdated,
|
|
1001
296
|
EntityFieldTypeBool,
|
|
@@ -1021,14 +316,12 @@ export {
|
|
|
1021
316
|
EntityFilterOperators,
|
|
1022
317
|
EntityOrgSchemaCreate,
|
|
1023
318
|
EntityOrgSchemaDrop,
|
|
1024
|
-
EntityRecordContext,
|
|
1025
319
|
EntityRecordCount,
|
|
1026
320
|
EntityRecordCreate,
|
|
1027
321
|
EntityRecordCreated,
|
|
1028
322
|
EntityRecordDelete,
|
|
1029
323
|
EntityRecordDeleted,
|
|
1030
324
|
EntityRecordGet,
|
|
1031
|
-
EntityRecordProvider,
|
|
1032
325
|
EntityRecordQuery,
|
|
1033
326
|
EntityRecordUpdate,
|
|
1034
327
|
EntityRecordUpdated,
|
|
@@ -1064,12 +357,6 @@ export {
|
|
|
1064
357
|
RecordChangeActionDeleted,
|
|
1065
358
|
RecordChangeActionUpdated,
|
|
1066
359
|
entityDefinitionReducer,
|
|
1067
|
-
entityRecordReducer
|
|
1068
|
-
useDebounce,
|
|
1069
|
-
useEntityDefinition,
|
|
1070
|
-
useEntityDefinitionContext,
|
|
1071
|
-
useEntityDefinitionDetails,
|
|
1072
|
-
useEntityRecord,
|
|
1073
|
-
useEntityRecordContext
|
|
360
|
+
entityRecordReducer
|
|
1074
361
|
};
|
|
1075
362
|
//# sourceMappingURL=index.mjs.map
|