@elqnt/entity 2.1.2 → 2.2.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/README.md +70 -19
- package/dist/api/index.d.mts +17 -2
- package/dist/api/index.d.ts +17 -2
- package/dist/api/index.js +4 -2
- package/dist/api/index.js.map +1 -1
- package/dist/api/index.mjs +3 -1
- package/dist/chunk-5BPHCJ2G.js +427 -0
- package/dist/chunk-5BPHCJ2G.js.map +1 -0
- package/dist/{chunk-SXBB42DJ.js → chunk-6SB5QDL5.js} +10 -2
- package/dist/chunk-6SB5QDL5.js.map +1 -0
- package/dist/chunk-F7ZN7FHI.mjs +427 -0
- package/dist/chunk-F7ZN7FHI.mjs.map +1 -0
- package/dist/{chunk-UHASYUCH.mjs → chunk-SHMUKUYC.mjs} +10 -2
- package/dist/{chunk-UHASYUCH.mjs.map → chunk-SHMUKUYC.mjs.map} +1 -1
- package/dist/hooks/index.d.mts +113 -18
- package/dist/hooks/index.d.ts +113 -18
- package/dist/hooks/index.js +13 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +14 -4
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -147
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -146
- package/dist/index.mjs.map +1 -1
- package/dist/models/index.js +108 -73
- package/dist/models/index.js.map +1 -1
- package/dist/models/index.mjs +108 -73
- package/dist/models/index.mjs.map +1 -1
- package/dist/use-entities-CC3WhBDv.d.ts +45 -0
- package/dist/use-entities-gK_B9I2n.d.mts +45 -0
- package/package.json +15 -13
- package/dist/chunk-4GC36G4D.js +0 -184
- package/dist/chunk-4GC36G4D.js.map +0 -1
- package/dist/chunk-GQJJP4YL.js +0 -204
- package/dist/chunk-GQJJP4YL.js.map +0 -1
- package/dist/chunk-JEDTIUWW.mjs +0 -204
- package/dist/chunk-JEDTIUWW.mjs.map +0 -1
- package/dist/chunk-LIACJMHV.mjs +0 -184
- package/dist/chunk-LIACJMHV.mjs.map +0 -1
- package/dist/chunk-SXBB42DJ.js.map +0 -1
package/README.md
CHANGED
|
@@ -106,30 +106,45 @@ React Component
|
|
|
106
106
|
|
|
107
107
|
| Hook | Description |
|
|
108
108
|
|------|-------------|
|
|
109
|
-
| `
|
|
109
|
+
| `useEntityDefinitions(options)` | Entity definition CRUD operations |
|
|
110
|
+
| `useEntityRecords(options)` | Entity record CRUD with bulk operations and count |
|
|
111
|
+
| `useEntities(options)` | Legacy combined hook (backward compatible) |
|
|
110
112
|
|
|
111
|
-
Use
|
|
113
|
+
**Recommended: Use specialized hooks for better separation of concerns:**
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { useEntityDefinitions, useEntityRecords } from "@elqnt/entity/hooks";
|
|
117
|
+
|
|
118
|
+
// For entity schema management
|
|
119
|
+
const { listDefinitions, getDefinition, createDefinition, updateDefinition, deleteDefinition, loading, error } = useEntityDefinitions({
|
|
120
|
+
baseUrl: config.apiGatewayUrl,
|
|
121
|
+
orgId: config.orgId,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// For entity record operations (scoped to a specific entity)
|
|
125
|
+
const { queryRecords, getRecord, createRecord, updateRecord, deleteRecord, countRecords, bulkCreate, bulkUpdate, bulkDelete, loading, error } = useEntityRecords({
|
|
126
|
+
baseUrl: config.apiGatewayUrl,
|
|
127
|
+
orgId: config.orgId,
|
|
128
|
+
entityName: "contacts",
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Legacy hook (still supported):**
|
|
112
133
|
|
|
113
134
|
```tsx
|
|
114
|
-
// Inside your custom hook
|
|
115
135
|
import { useEntities } from "@elqnt/entity/hooks";
|
|
116
136
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
} = useEntities({ baseUrl, orgId });
|
|
129
|
-
|
|
130
|
-
// Transform and expose domain-specific functions
|
|
131
|
-
// ...
|
|
132
|
-
}
|
|
137
|
+
const {
|
|
138
|
+
queryRecords, // Query multiple records with filters/pagination
|
|
139
|
+
getRecord, // Get single record by ID
|
|
140
|
+
createRecord, // Create new record
|
|
141
|
+
updateRecord, // Update existing record
|
|
142
|
+
deleteRecord, // Delete record
|
|
143
|
+
listDefinitions,// List entity definitions
|
|
144
|
+
getDefinition, // Get entity definition by name
|
|
145
|
+
loading, // Loading state
|
|
146
|
+
error, // Error message
|
|
147
|
+
} = useEntities({ baseUrl, orgId });
|
|
133
148
|
```
|
|
134
149
|
|
|
135
150
|
### `/api` - API Functions
|
|
@@ -159,9 +174,45 @@ import {
|
|
|
159
174
|
|
|
160
175
|
// Count
|
|
161
176
|
countEntityRecordsApi,
|
|
177
|
+
|
|
178
|
+
// Provisioning
|
|
179
|
+
provisionEntitiesApi,
|
|
162
180
|
} from "@elqnt/entity/api";
|
|
163
181
|
```
|
|
164
182
|
|
|
183
|
+
### Provisioning Entities (Admin)
|
|
184
|
+
|
|
185
|
+
Use `provisionEntitiesApi` to set up default entity definitions for an organization:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { provisionEntitiesApi } from "@elqnt/entity/api";
|
|
189
|
+
import type { EntityDefinition } from "@elqnt/entity/models";
|
|
190
|
+
|
|
191
|
+
const definitions: EntityDefinition[] = [{
|
|
192
|
+
name: "ticket",
|
|
193
|
+
displayName: "Support Ticket",
|
|
194
|
+
description: "Customer support tickets",
|
|
195
|
+
schema: {
|
|
196
|
+
type: "object",
|
|
197
|
+
properties: {
|
|
198
|
+
title: { type: "string" },
|
|
199
|
+
status: { type: "string", enum: ["open", "closed"] },
|
|
200
|
+
},
|
|
201
|
+
required: ["title", "status"],
|
|
202
|
+
},
|
|
203
|
+
isActive: true,
|
|
204
|
+
}];
|
|
205
|
+
|
|
206
|
+
const result = await provisionEntitiesApi(definitions, {
|
|
207
|
+
baseUrl: "https://api.elqnt.ai",
|
|
208
|
+
orgId: "org-uuid",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (result.data?.success) {
|
|
212
|
+
console.log(`Created: ${result.data.created}, Updated: ${result.data.updated}`);
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
165
216
|
### `/models` - TypeScript Types
|
|
166
217
|
|
|
167
218
|
Types generated from Go via tygo.
|
package/dist/api/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiClientOptions, ApiResponse } from '@elqnt/api-client';
|
|
2
2
|
import { ResponseMetadata } from '@elqnt/types';
|
|
3
|
-
import {
|
|
3
|
+
import { EntityRecord, EntityDefinition, EntityDefinitionResponse, EntityRecordResponse, ListEntityDefinitionsResponse, ListEntityRecordsResponse } from '../models/index.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Entity API functions
|
|
@@ -41,5 +41,20 @@ declare function countEntityRecordsApi(entityName: string, filters: Record<strin
|
|
|
41
41
|
count: number;
|
|
42
42
|
metadata: ResponseMetadata;
|
|
43
43
|
}>>;
|
|
44
|
+
interface ProvisionEntitiesResponse {
|
|
45
|
+
created: number;
|
|
46
|
+
updated: number;
|
|
47
|
+
errors: string[];
|
|
48
|
+
success: boolean;
|
|
49
|
+
metadata: ResponseMetadata;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Provision entity definitions for an organization.
|
|
53
|
+
* Creates or updates entity definitions in bulk.
|
|
54
|
+
*
|
|
55
|
+
* @param definitions - Array of EntityDefinition to provision
|
|
56
|
+
* @param options - API client options (baseUrl, orgId)
|
|
57
|
+
*/
|
|
58
|
+
declare function provisionEntitiesApi(definitions: EntityDefinition[], options: ApiClientOptions): Promise<ApiResponse<ProvisionEntitiesResponse>>;
|
|
44
59
|
|
|
45
|
-
export { bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi };
|
|
60
|
+
export { type ProvisionEntitiesResponse, bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, provisionEntitiesApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi };
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiClientOptions, ApiResponse } from '@elqnt/api-client';
|
|
2
2
|
import { ResponseMetadata } from '@elqnt/types';
|
|
3
|
-
import {
|
|
3
|
+
import { EntityRecord, EntityDefinition, EntityDefinitionResponse, EntityRecordResponse, ListEntityDefinitionsResponse, ListEntityRecordsResponse } from '../models/index.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Entity API functions
|
|
@@ -41,5 +41,20 @@ declare function countEntityRecordsApi(entityName: string, filters: Record<strin
|
|
|
41
41
|
count: number;
|
|
42
42
|
metadata: ResponseMetadata;
|
|
43
43
|
}>>;
|
|
44
|
+
interface ProvisionEntitiesResponse {
|
|
45
|
+
created: number;
|
|
46
|
+
updated: number;
|
|
47
|
+
errors: string[];
|
|
48
|
+
success: boolean;
|
|
49
|
+
metadata: ResponseMetadata;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Provision entity definitions for an organization.
|
|
53
|
+
* Creates or updates entity definitions in bulk.
|
|
54
|
+
*
|
|
55
|
+
* @param definitions - Array of EntityDefinition to provision
|
|
56
|
+
* @param options - API client options (baseUrl, orgId)
|
|
57
|
+
*/
|
|
58
|
+
declare function provisionEntitiesApi(definitions: EntityDefinition[], options: ApiClientOptions): Promise<ApiResponse<ProvisionEntitiesResponse>>;
|
|
44
59
|
|
|
45
|
-
export { bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi };
|
|
60
|
+
export { type ProvisionEntitiesResponse, bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, provisionEntitiesApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi };
|
package/dist/api/index.js
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
var _chunkSXBB42DJjs = require('../chunk-SXBB42DJ.js');
|
|
18
17
|
|
|
18
|
+
var _chunk6SB5QDL5js = require('../chunk-6SB5QDL5.js');
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
@@ -30,5 +30,7 @@ var _chunkSXBB42DJjs = require('../chunk-SXBB42DJ.js');
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
exports.bulkCreateEntityRecordsApi = _chunk6SB5QDL5js.bulkCreateEntityRecordsApi; exports.bulkDeleteEntityRecordsApi = _chunk6SB5QDL5js.bulkDeleteEntityRecordsApi; exports.bulkUpdateEntityRecordsApi = _chunk6SB5QDL5js.bulkUpdateEntityRecordsApi; exports.countEntityRecordsApi = _chunk6SB5QDL5js.countEntityRecordsApi; exports.createEntityDefinitionApi = _chunk6SB5QDL5js.createEntityDefinitionApi; exports.createEntityRecordApi = _chunk6SB5QDL5js.createEntityRecordApi; exports.deleteEntityDefinitionApi = _chunk6SB5QDL5js.deleteEntityDefinitionApi; exports.deleteEntityRecordApi = _chunk6SB5QDL5js.deleteEntityRecordApi; exports.getEntityDefinitionApi = _chunk6SB5QDL5js.getEntityDefinitionApi; exports.getEntityRecordApi = _chunk6SB5QDL5js.getEntityRecordApi; exports.listEntityDefinitionsApi = _chunk6SB5QDL5js.listEntityDefinitionsApi; exports.provisionEntitiesApi = _chunk6SB5QDL5js.provisionEntitiesApi; exports.queryEntityRecordsApi = _chunk6SB5QDL5js.queryEntityRecordsApi; exports.updateEntityDefinitionApi = _chunk6SB5QDL5js.updateEntityDefinitionApi; exports.updateEntityRecordApi = _chunk6SB5QDL5js.updateEntityRecordApi;
|
|
34
36
|
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/eloquent
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/api/index.js"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6mCAAC","file":"/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/api/index.js"}
|
package/dist/api/index.mjs
CHANGED
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
getEntityDefinitionApi,
|
|
12
12
|
getEntityRecordApi,
|
|
13
13
|
listEntityDefinitionsApi,
|
|
14
|
+
provisionEntitiesApi,
|
|
14
15
|
queryEntityRecordsApi,
|
|
15
16
|
updateEntityDefinitionApi,
|
|
16
17
|
updateEntityRecordApi
|
|
17
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-SHMUKUYC.mjs";
|
|
18
19
|
export {
|
|
19
20
|
bulkCreateEntityRecordsApi,
|
|
20
21
|
bulkDeleteEntityRecordsApi,
|
|
@@ -27,6 +28,7 @@ export {
|
|
|
27
28
|
getEntityDefinitionApi,
|
|
28
29
|
getEntityRecordApi,
|
|
29
30
|
listEntityDefinitionsApi,
|
|
31
|
+
provisionEntitiesApi,
|
|
30
32
|
queryEntityRecordsApi,
|
|
31
33
|
updateEntityDefinitionApi,
|
|
32
34
|
updateEntityRecordApi
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunk6SB5QDL5js = require('./chunk-6SB5QDL5.js');
|
|
18
|
+
|
|
19
|
+
// hooks/use-entity-definitions.ts
|
|
20
|
+
var _react = require('react');
|
|
21
|
+
|
|
22
|
+
// hooks/use-async.ts
|
|
23
|
+
|
|
24
|
+
function useAsync(asyncFn, transform, defaultValue, options = {}) {
|
|
25
|
+
const { resetErrorOnRequest = true } = options;
|
|
26
|
+
const [loading, setLoading] = _react.useState.call(void 0, false);
|
|
27
|
+
const [error, setError] = _react.useState.call(void 0, null);
|
|
28
|
+
const execute = _react.useCallback.call(void 0,
|
|
29
|
+
async (...args) => {
|
|
30
|
+
setLoading(true);
|
|
31
|
+
if (resetErrorOnRequest) {
|
|
32
|
+
setError(null);
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const response = await asyncFn(...args);
|
|
36
|
+
if (response.error) {
|
|
37
|
+
setError(response.error);
|
|
38
|
+
return defaultValue;
|
|
39
|
+
}
|
|
40
|
+
if (!response.data) {
|
|
41
|
+
return defaultValue;
|
|
42
|
+
}
|
|
43
|
+
return transform(response.data);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
const message = err instanceof Error ? err.message : "An error occurred";
|
|
46
|
+
setError(message);
|
|
47
|
+
return defaultValue;
|
|
48
|
+
} finally {
|
|
49
|
+
setLoading(false);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[asyncFn, transform, defaultValue, resetErrorOnRequest]
|
|
53
|
+
);
|
|
54
|
+
return { execute, loading, error };
|
|
55
|
+
}
|
|
56
|
+
function useApiAsync(asyncFn, transform, defaultValue) {
|
|
57
|
+
return useAsync(asyncFn, transform, defaultValue);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// hooks/use-options-ref.ts
|
|
61
|
+
|
|
62
|
+
function useOptionsRef(options) {
|
|
63
|
+
const optionsRef = _react.useRef.call(void 0, options);
|
|
64
|
+
_react.useEffect.call(void 0, () => {
|
|
65
|
+
optionsRef.current = options;
|
|
66
|
+
}, [options]);
|
|
67
|
+
return optionsRef;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// hooks/use-entity-definitions.ts
|
|
71
|
+
function useEntityDefinitions(options) {
|
|
72
|
+
const optionsRef = useOptionsRef(options);
|
|
73
|
+
const { execute: listDefinitions, loading: listLoading, error: listError } = useApiAsync(
|
|
74
|
+
() => _chunk6SB5QDL5js.listEntityDefinitionsApi.call(void 0, optionsRef.current),
|
|
75
|
+
(data) => data.definitions || [],
|
|
76
|
+
[]
|
|
77
|
+
);
|
|
78
|
+
const { execute: getDefinition, loading: getLoading, error: getError } = useApiAsync(
|
|
79
|
+
(entityName) => _chunk6SB5QDL5js.getEntityDefinitionApi.call(void 0, entityName, optionsRef.current),
|
|
80
|
+
(data) => data.definition || null,
|
|
81
|
+
null
|
|
82
|
+
);
|
|
83
|
+
const { execute: createDefinition, loading: createLoading, error: createError } = useApiAsync(
|
|
84
|
+
(definition) => _chunk6SB5QDL5js.createEntityDefinitionApi.call(void 0, definition, optionsRef.current),
|
|
85
|
+
(data) => data.definition || null,
|
|
86
|
+
null
|
|
87
|
+
);
|
|
88
|
+
const { execute: updateDefinition, loading: updateLoading, error: updateError } = useApiAsync(
|
|
89
|
+
(entityName, definition) => _chunk6SB5QDL5js.updateEntityDefinitionApi.call(void 0, entityName, definition, optionsRef.current),
|
|
90
|
+
(data) => data.definition || null,
|
|
91
|
+
null
|
|
92
|
+
);
|
|
93
|
+
const { execute: deleteDefinition, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
94
|
+
(entityName) => _chunk6SB5QDL5js.deleteEntityDefinitionApi.call(void 0, entityName, optionsRef.current),
|
|
95
|
+
(data) => data.success,
|
|
96
|
+
false
|
|
97
|
+
);
|
|
98
|
+
const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading;
|
|
99
|
+
const error = listError || getError || createError || updateError || deleteError;
|
|
100
|
+
return _react.useMemo.call(void 0,
|
|
101
|
+
() => ({
|
|
102
|
+
loading,
|
|
103
|
+
error,
|
|
104
|
+
listDefinitions,
|
|
105
|
+
getDefinition,
|
|
106
|
+
createDefinition,
|
|
107
|
+
updateDefinition,
|
|
108
|
+
deleteDefinition
|
|
109
|
+
}),
|
|
110
|
+
[loading, error, listDefinitions, getDefinition, createDefinition, updateDefinition, deleteDefinition]
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// hooks/use-entity-records.ts
|
|
115
|
+
|
|
116
|
+
function useEntityRecords(options) {
|
|
117
|
+
const optionsRef = useOptionsRef(options);
|
|
118
|
+
const getEntityName = () => optionsRef.current.entityName;
|
|
119
|
+
const getApiOptions = () => {
|
|
120
|
+
const { entityName: _, ...apiOptions } = optionsRef.current;
|
|
121
|
+
return apiOptions;
|
|
122
|
+
};
|
|
123
|
+
const { execute: queryRecords, loading: queryLoading, error: queryError } = useApiAsync(
|
|
124
|
+
(params) => {
|
|
125
|
+
const queryParams = {
|
|
126
|
+
page: _optionalChain([params, 'optionalAccess', _2 => _2.page]) || 1,
|
|
127
|
+
pageSize: _optionalChain([params, 'optionalAccess', _3 => _3.pageSize]) || 20
|
|
128
|
+
};
|
|
129
|
+
if (_optionalChain([params, 'optionalAccess', _4 => _4.filters])) {
|
|
130
|
+
queryParams.filters = JSON.stringify(params.filters);
|
|
131
|
+
}
|
|
132
|
+
if (_optionalChain([params, 'optionalAccess', _5 => _5.sortBy])) {
|
|
133
|
+
queryParams.sortBy = params.sortBy;
|
|
134
|
+
}
|
|
135
|
+
if (_optionalChain([params, 'optionalAccess', _6 => _6.sortOrder])) {
|
|
136
|
+
queryParams.sortOrder = params.sortOrder;
|
|
137
|
+
}
|
|
138
|
+
return _chunk6SB5QDL5js.queryEntityRecordsApi.call(void 0, getEntityName(), queryParams, getApiOptions());
|
|
139
|
+
},
|
|
140
|
+
(data) => {
|
|
141
|
+
if (_optionalChain([data, 'optionalAccess', _7 => _7.records, 'optionalAccess', _8 => _8.items])) {
|
|
142
|
+
return {
|
|
143
|
+
records: data.records.items,
|
|
144
|
+
total: data.records.totalCount,
|
|
145
|
+
page: data.records.currentPage,
|
|
146
|
+
pageSize: data.records.pageSize
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
records: _optionalChain([data, 'optionalAccess', _9 => _9.records]) || [],
|
|
151
|
+
total: _optionalChain([data, 'optionalAccess', _10 => _10.total]) || 0,
|
|
152
|
+
page: _optionalChain([data, 'optionalAccess', _11 => _11.page]) || 1,
|
|
153
|
+
pageSize: _optionalChain([data, 'optionalAccess', _12 => _12.pageSize]) || 20
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
{ records: [], total: 0, page: 1, pageSize: 20 }
|
|
157
|
+
);
|
|
158
|
+
const { execute: getRecord, loading: getLoading, error: getError } = useApiAsync(
|
|
159
|
+
(recordId) => _chunk6SB5QDL5js.getEntityRecordApi.call(void 0, getEntityName(), recordId, getApiOptions()),
|
|
160
|
+
(data) => data.record || null,
|
|
161
|
+
null
|
|
162
|
+
);
|
|
163
|
+
const { execute: createRecord, loading: createLoading, error: createError } = useApiAsync(
|
|
164
|
+
(record) => _chunk6SB5QDL5js.createEntityRecordApi.call(void 0, getEntityName(), record, getApiOptions()),
|
|
165
|
+
(data) => data.record || null,
|
|
166
|
+
null
|
|
167
|
+
);
|
|
168
|
+
const { execute: updateRecord, loading: updateLoading, error: updateError } = useApiAsync(
|
|
169
|
+
(recordId, record) => _chunk6SB5QDL5js.updateEntityRecordApi.call(void 0, getEntityName(), recordId, record, getApiOptions()),
|
|
170
|
+
(data) => data.record || null,
|
|
171
|
+
null
|
|
172
|
+
);
|
|
173
|
+
const { execute: deleteRecord, loading: deleteLoading, error: deleteError } = useApiAsync(
|
|
174
|
+
(recordId) => _chunk6SB5QDL5js.deleteEntityRecordApi.call(void 0, getEntityName(), recordId, getApiOptions()),
|
|
175
|
+
(data) => data.success,
|
|
176
|
+
false
|
|
177
|
+
);
|
|
178
|
+
const { execute: countRecords, loading: countLoading, error: countError } = useApiAsync(
|
|
179
|
+
(filters) => _chunk6SB5QDL5js.countEntityRecordsApi.call(void 0, getEntityName(), filters || {}, getApiOptions()),
|
|
180
|
+
(data) => data.count,
|
|
181
|
+
0
|
|
182
|
+
);
|
|
183
|
+
const { execute: bulkCreate, loading: bulkCreateLoading, error: bulkCreateError } = useApiAsync(
|
|
184
|
+
(records) => _chunk6SB5QDL5js.bulkCreateEntityRecordsApi.call(void 0, getEntityName(), records, getApiOptions()),
|
|
185
|
+
(data) => ({ records: data.records, success: true }),
|
|
186
|
+
{ success: false }
|
|
187
|
+
);
|
|
188
|
+
const { execute: bulkUpdate, loading: bulkUpdateLoading, error: bulkUpdateError } = useApiAsync(
|
|
189
|
+
(records) => _chunk6SB5QDL5js.bulkUpdateEntityRecordsApi.call(void 0, getEntityName(), records, getApiOptions()),
|
|
190
|
+
(data) => ({ records: data.records, success: true }),
|
|
191
|
+
{ success: false }
|
|
192
|
+
);
|
|
193
|
+
const { execute: bulkDelete, loading: bulkDeleteLoading, error: bulkDeleteError } = useApiAsync(
|
|
194
|
+
(recordIds) => _chunk6SB5QDL5js.bulkDeleteEntityRecordsApi.call(void 0, getEntityName(), recordIds, getApiOptions()),
|
|
195
|
+
(data) => data.success,
|
|
196
|
+
false
|
|
197
|
+
);
|
|
198
|
+
const loading = queryLoading || getLoading || createLoading || updateLoading || deleteLoading || countLoading || bulkCreateLoading || bulkUpdateLoading || bulkDeleteLoading;
|
|
199
|
+
const error = queryError || getError || createError || updateError || deleteError || countError || bulkCreateError || bulkUpdateError || bulkDeleteError;
|
|
200
|
+
return _react.useMemo.call(void 0,
|
|
201
|
+
() => ({
|
|
202
|
+
loading,
|
|
203
|
+
error,
|
|
204
|
+
queryRecords,
|
|
205
|
+
getRecord,
|
|
206
|
+
createRecord,
|
|
207
|
+
updateRecord,
|
|
208
|
+
deleteRecord,
|
|
209
|
+
countRecords,
|
|
210
|
+
bulkCreate,
|
|
211
|
+
bulkUpdate,
|
|
212
|
+
bulkDelete
|
|
213
|
+
}),
|
|
214
|
+
[
|
|
215
|
+
loading,
|
|
216
|
+
error,
|
|
217
|
+
queryRecords,
|
|
218
|
+
getRecord,
|
|
219
|
+
createRecord,
|
|
220
|
+
updateRecord,
|
|
221
|
+
deleteRecord,
|
|
222
|
+
countRecords,
|
|
223
|
+
bulkCreate,
|
|
224
|
+
bulkUpdate,
|
|
225
|
+
bulkDelete
|
|
226
|
+
]
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// hooks/use-entities.ts
|
|
231
|
+
|
|
232
|
+
function useEntities(options) {
|
|
233
|
+
const [loading, setLoading] = _react.useState.call(void 0, false);
|
|
234
|
+
const [error, setError] = _react.useState.call(void 0, null);
|
|
235
|
+
const listDefinitions = _react.useCallback.call(void 0, async () => {
|
|
236
|
+
setLoading(true);
|
|
237
|
+
setError(null);
|
|
238
|
+
try {
|
|
239
|
+
const response = await _chunk6SB5QDL5js.listEntityDefinitionsApi.call(void 0, options);
|
|
240
|
+
if (response.error) {
|
|
241
|
+
setError(response.error);
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
return _optionalChain([response, 'access', _13 => _13.data, 'optionalAccess', _14 => _14.definitions]) || [];
|
|
245
|
+
} catch (err) {
|
|
246
|
+
const message = err instanceof Error ? err.message : "Failed to load definitions";
|
|
247
|
+
setError(message);
|
|
248
|
+
return [];
|
|
249
|
+
} finally {
|
|
250
|
+
setLoading(false);
|
|
251
|
+
}
|
|
252
|
+
}, [options]);
|
|
253
|
+
const getDefinition = _react.useCallback.call(void 0,
|
|
254
|
+
async (entityName) => {
|
|
255
|
+
setLoading(true);
|
|
256
|
+
setError(null);
|
|
257
|
+
try {
|
|
258
|
+
const response = await _chunk6SB5QDL5js.getEntityDefinitionApi.call(void 0, entityName, options);
|
|
259
|
+
if (response.error) {
|
|
260
|
+
setError(response.error);
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return _optionalChain([response, 'access', _15 => _15.data, 'optionalAccess', _16 => _16.definition]) || null;
|
|
264
|
+
} catch (err) {
|
|
265
|
+
const message = err instanceof Error ? err.message : "Failed to get definition";
|
|
266
|
+
setError(message);
|
|
267
|
+
return null;
|
|
268
|
+
} finally {
|
|
269
|
+
setLoading(false);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
[options]
|
|
273
|
+
);
|
|
274
|
+
const queryRecords = _react.useCallback.call(void 0,
|
|
275
|
+
async (entityName, query = {}) => {
|
|
276
|
+
setLoading(true);
|
|
277
|
+
setError(null);
|
|
278
|
+
try {
|
|
279
|
+
const queryParams = {
|
|
280
|
+
page: query.page || 1,
|
|
281
|
+
pageSize: query.pageSize || 20
|
|
282
|
+
};
|
|
283
|
+
if (query.filters) {
|
|
284
|
+
queryParams.filters = JSON.stringify(query.filters);
|
|
285
|
+
}
|
|
286
|
+
if (query.sortBy) {
|
|
287
|
+
queryParams.sortBy = query.sortBy;
|
|
288
|
+
}
|
|
289
|
+
if (query.sortOrder) {
|
|
290
|
+
queryParams.sortOrder = query.sortOrder;
|
|
291
|
+
}
|
|
292
|
+
const response = await _chunk6SB5QDL5js.queryEntityRecordsApi.call(void 0, entityName, queryParams, options);
|
|
293
|
+
if (response.error) {
|
|
294
|
+
setError(response.error);
|
|
295
|
+
return { records: [], total: 0, page: 1, pageSize: 20 };
|
|
296
|
+
}
|
|
297
|
+
const data = response.data;
|
|
298
|
+
if (_optionalChain([data, 'optionalAccess', _17 => _17.records, 'optionalAccess', _18 => _18.items])) {
|
|
299
|
+
return {
|
|
300
|
+
records: data.records.items,
|
|
301
|
+
total: data.records.totalCount,
|
|
302
|
+
page: data.records.currentPage,
|
|
303
|
+
pageSize: data.records.pageSize
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
records: _optionalChain([data, 'optionalAccess', _19 => _19.records]) || [],
|
|
308
|
+
total: _optionalChain([data, 'optionalAccess', _20 => _20.total]) || 0,
|
|
309
|
+
page: _optionalChain([data, 'optionalAccess', _21 => _21.page]) || 1,
|
|
310
|
+
pageSize: _optionalChain([data, 'optionalAccess', _22 => _22.pageSize]) || 20
|
|
311
|
+
};
|
|
312
|
+
} catch (err) {
|
|
313
|
+
const message = err instanceof Error ? err.message : "Failed to query records";
|
|
314
|
+
setError(message);
|
|
315
|
+
return { records: [], total: 0, page: 1, pageSize: 20 };
|
|
316
|
+
} finally {
|
|
317
|
+
setLoading(false);
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
[options]
|
|
321
|
+
);
|
|
322
|
+
const getRecord = _react.useCallback.call(void 0,
|
|
323
|
+
async (entityName, recordId) => {
|
|
324
|
+
setLoading(true);
|
|
325
|
+
setError(null);
|
|
326
|
+
try {
|
|
327
|
+
const response = await _chunk6SB5QDL5js.getEntityRecordApi.call(void 0, entityName, recordId, options);
|
|
328
|
+
if (response.error) {
|
|
329
|
+
setError(response.error);
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
return _optionalChain([response, 'access', _23 => _23.data, 'optionalAccess', _24 => _24.record]) || null;
|
|
333
|
+
} catch (err) {
|
|
334
|
+
const message = err instanceof Error ? err.message : "Failed to get record";
|
|
335
|
+
setError(message);
|
|
336
|
+
return null;
|
|
337
|
+
} finally {
|
|
338
|
+
setLoading(false);
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
[options]
|
|
342
|
+
);
|
|
343
|
+
const createRecord = _react.useCallback.call(void 0,
|
|
344
|
+
async (entityName, record) => {
|
|
345
|
+
setLoading(true);
|
|
346
|
+
setError(null);
|
|
347
|
+
try {
|
|
348
|
+
const response = await _chunk6SB5QDL5js.createEntityRecordApi.call(void 0, entityName, record, options);
|
|
349
|
+
if (response.error) {
|
|
350
|
+
setError(response.error);
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return _optionalChain([response, 'access', _25 => _25.data, 'optionalAccess', _26 => _26.record]) || null;
|
|
354
|
+
} catch (err) {
|
|
355
|
+
const message = err instanceof Error ? err.message : "Failed to create record";
|
|
356
|
+
setError(message);
|
|
357
|
+
return null;
|
|
358
|
+
} finally {
|
|
359
|
+
setLoading(false);
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
[options]
|
|
363
|
+
);
|
|
364
|
+
const updateRecord = _react.useCallback.call(void 0,
|
|
365
|
+
async (entityName, recordId, record) => {
|
|
366
|
+
setLoading(true);
|
|
367
|
+
setError(null);
|
|
368
|
+
try {
|
|
369
|
+
const response = await _chunk6SB5QDL5js.updateEntityRecordApi.call(void 0, entityName, recordId, record, options);
|
|
370
|
+
if (response.error) {
|
|
371
|
+
setError(response.error);
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
return _optionalChain([response, 'access', _27 => _27.data, 'optionalAccess', _28 => _28.record]) || null;
|
|
375
|
+
} catch (err) {
|
|
376
|
+
const message = err instanceof Error ? err.message : "Failed to update record";
|
|
377
|
+
setError(message);
|
|
378
|
+
return null;
|
|
379
|
+
} finally {
|
|
380
|
+
setLoading(false);
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
[options]
|
|
384
|
+
);
|
|
385
|
+
const deleteRecord = _react.useCallback.call(void 0,
|
|
386
|
+
async (entityName, recordId) => {
|
|
387
|
+
setLoading(true);
|
|
388
|
+
setError(null);
|
|
389
|
+
try {
|
|
390
|
+
const response = await _chunk6SB5QDL5js.deleteEntityRecordApi.call(void 0, entityName, recordId, options);
|
|
391
|
+
if (response.error) {
|
|
392
|
+
setError(response.error);
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
return true;
|
|
396
|
+
} catch (err) {
|
|
397
|
+
const message = err instanceof Error ? err.message : "Failed to delete record";
|
|
398
|
+
setError(message);
|
|
399
|
+
return false;
|
|
400
|
+
} finally {
|
|
401
|
+
setLoading(false);
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
[options]
|
|
405
|
+
);
|
|
406
|
+
return {
|
|
407
|
+
loading,
|
|
408
|
+
error,
|
|
409
|
+
listDefinitions,
|
|
410
|
+
getDefinition,
|
|
411
|
+
queryRecords,
|
|
412
|
+
getRecord,
|
|
413
|
+
createRecord,
|
|
414
|
+
updateRecord,
|
|
415
|
+
deleteRecord
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
exports.useAsync = useAsync; exports.useApiAsync = useApiAsync; exports.useOptionsRef = useOptionsRef; exports.useEntityDefinitions = useEntityDefinitions; exports.useEntityRecords = useEntityRecords; exports.useEntities = useEntities;
|
|
427
|
+
//# sourceMappingURL=chunk-5BPHCJ2G.js.map
|