@elqnt/entity 2.1.3 → 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/chunk-5BPHCJ2G.js +427 -0
- package/dist/chunk-5BPHCJ2G.js.map +1 -0
- package/dist/chunk-F7ZN7FHI.mjs +427 -0
- package/dist/chunk-F7ZN7FHI.mjs.map +1 -0
- package/dist/hooks/index.d.mts +114 -19
- package/dist/hooks/index.d.ts +114 -19
- package/dist/hooks/index.js +12 -2
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +13 -3
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/use-entities-CC3WhBDv.d.ts +45 -0
- package/dist/use-entities-gK_B9I2n.d.mts +45 -0
- package/package.json +4 -4
- package/dist/chunk-ESJH4DJM.js +0 -204
- package/dist/chunk-ESJH4DJM.js.map +0 -1
- package/dist/chunk-OIVRV2UT.mjs +0 -204
- package/dist/chunk-OIVRV2UT.mjs.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.
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/chunk-5BPHCJ2G.js","../hooks/use-entity-definitions.ts","../hooks/use-async.ts","../hooks/use-options-ref.ts","../hooks/use-entity-records.ts","../hooks/use-entities.ts"],"names":["useMemo","useState","useCallback"],"mappings":"AAAA,ylBAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACA;ACVA,8BAAwB;ADYxB;AACA;AEfA;AAoCO,SAAS,QAAA,CACd,OAAA,EACA,SAAA,EACA,YAAA,EACA,QAAA,EAA2B,CAAC,CAAA,EACI;AAChC,EAAA,MAAM,EAAE,oBAAA,EAAsB,KAAK,EAAA,EAAI,OAAA;AACvC,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,EAAA,EAAI,6BAAA,KAAc,CAAA;AAC5C,EAAA,M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unk-5BPHCJ2G.js","sourcesContent":[null,"\"use client\";\n\n/**\n * Entity definition hooks for React applications\n *\n * Provides React hooks for entity definition CRUD operations with loading/error states.\n */\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { EntityDefinition } from \"../models\";\nimport {\n listEntityDefinitionsApi,\n getEntityDefinitionApi,\n createEntityDefinitionApi,\n updateEntityDefinitionApi,\n deleteEntityDefinitionApi,\n} from \"../api\";\nimport { useApiAsync } from \"./use-async\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport type UseEntityDefinitionsOptions = ApiClientOptions;\n\n// =============================================================================\n// USE ENTITY DEFINITIONS HOOK\n// =============================================================================\n\n/**\n * Hook for entity definition CRUD operations\n *\n * @example\n * ```tsx\n * const { loading, error, listDefinitions, getDefinition, createDefinition } = useEntityDefinitions({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * });\n *\n * const definitions = await listDefinitions();\n * const definition = await getDefinition(\"contacts\");\n * const newDef = await createDefinition({ name: \"leads\", title: \"Leads\" });\n * ```\n */\nexport function useEntityDefinitions(options: UseEntityDefinitionsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const { execute: listDefinitions, loading: listLoading, error: listError } = useApiAsync(\n () => listEntityDefinitionsApi(optionsRef.current),\n (data) => data.definitions || [],\n [] as EntityDefinition[]\n );\n\n const { execute: getDefinition, loading: getLoading, error: getError } = useApiAsync(\n (entityName: string) => getEntityDefinitionApi(entityName, optionsRef.current),\n (data) => data.definition || null,\n null as EntityDefinition | null\n );\n\n const { execute: createDefinition, loading: createLoading, error: createError } = useApiAsync(\n (definition: Partial<EntityDefinition>) =>\n createEntityDefinitionApi(definition, optionsRef.current),\n (data) => data.definition || null,\n null as EntityDefinition | null\n );\n\n const { execute: updateDefinition, loading: updateLoading, error: updateError } = useApiAsync(\n (entityName: string, definition: Partial<EntityDefinition>) =>\n updateEntityDefinitionApi(entityName, definition, optionsRef.current),\n (data) => data.definition || null,\n null as EntityDefinition | null\n );\n\n const { execute: deleteDefinition, loading: deleteLoading, error: deleteError } = useApiAsync(\n (entityName: string) => deleteEntityDefinitionApi(entityName, optionsRef.current),\n (data) => data.success,\n false\n );\n\n const loading = listLoading || getLoading || createLoading || updateLoading || deleteLoading;\n const error = listError || getError || createError || updateError || deleteError;\n\n return useMemo(\n () => ({\n loading,\n error,\n listDefinitions,\n getDefinition,\n createDefinition,\n updateDefinition,\n deleteDefinition,\n }),\n [loading, error, listDefinitions, getDefinition, createDefinition, updateDefinition, deleteDefinition]\n );\n}\n","\"use client\";\n\n/**\n * Async operation hooks with loading/error state management\n */\n\nimport { useState, useCallback } from \"react\";\nimport type { ApiResponse } from \"@elqnt/api-client\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport interface UseAsyncOptions {\n /** Reset error on new request */\n resetErrorOnRequest?: boolean;\n}\n\nexport interface UseAsyncReturn<TArgs extends unknown[], TResult> {\n execute: (...args: TArgs) => Promise<TResult>;\n loading: boolean;\n error: string | null;\n}\n\n// =============================================================================\n// USE ASYNC HOOK\n// =============================================================================\n\n/**\n * Generic async operation hook with loading/error states\n *\n * @example\n * ```tsx\n * const { execute: fetchUser, loading, error } = useAsync(\n * (userId: string) => getUserApi(userId, options),\n * (data) => data.user,\n * null\n * );\n *\n * const user = await fetchUser(\"user-123\");\n * ```\n */\nexport function useAsync<TArgs extends unknown[], TData, TResult>(\n asyncFn: (...args: TArgs) => Promise<ApiResponse<TData>>,\n transform: (data: TData) => TResult,\n defaultValue: TResult,\n options: UseAsyncOptions = {}\n): UseAsyncReturn<TArgs, TResult> {\n const { resetErrorOnRequest = true } = options;\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const execute = useCallback(\n async (...args: TArgs): Promise<TResult> => {\n setLoading(true);\n if (resetErrorOnRequest) {\n setError(null);\n }\n\n try {\n const response = await asyncFn(...args);\n\n if (response.error) {\n setError(response.error);\n return defaultValue;\n }\n\n if (!response.data) {\n return defaultValue;\n }\n\n return transform(response.data);\n } catch (err) {\n const message = err instanceof Error ? err.message : \"An error occurred\";\n setError(message);\n return defaultValue;\n } finally {\n setLoading(false);\n }\n },\n [asyncFn, transform, defaultValue, resetErrorOnRequest]\n );\n\n return { execute, loading, error };\n}\n\n/**\n * Simplified async hook for API operations\n *\n * @example\n * ```tsx\n * const { execute: getUsers, loading, error } = useApiAsync(\n * () => listUsersApi(optionsRef.current),\n * (data) => data.users,\n * []\n * );\n * ```\n */\nexport function useApiAsync<TArgs extends unknown[], TData, TResult>(\n asyncFn: (...args: TArgs) => Promise<ApiResponse<TData>>,\n transform: (data: TData) => TResult,\n defaultValue: TResult\n): UseAsyncReturn<TArgs, TResult> {\n return useAsync(asyncFn, transform, defaultValue);\n}\n","\"use client\";\n\n/**\n * Options ref hook for stable callback references\n *\n * Keeps options in a ref to avoid stale closures in callbacks\n * while maintaining referential stability.\n */\n\nimport { useRef, useEffect } from \"react\";\n\n/**\n * Hook that keeps options in a ref for stable callback access\n *\n * @example\n * ```tsx\n * const optionsRef = useOptionsRef({ baseUrl, orgId });\n *\n * const fetchData = useCallback(async () => {\n * // Always accesses latest options without recreating callback\n * await api.fetch(optionsRef.current);\n * }, []); // No dependencies needed\n * ```\n */\nexport function useOptionsRef<T>(options: T) {\n const optionsRef = useRef(options);\n\n useEffect(() => {\n optionsRef.current = options;\n }, [options]);\n\n return optionsRef;\n}\n","\"use client\";\n\n/**\n * Entity record hooks for React applications\n *\n * Provides React hooks for entity record CRUD operations with loading/error states.\n */\n\nimport { useMemo } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { EntityRecord } from \"../models\";\nimport {\n queryEntityRecordsApi,\n getEntityRecordApi,\n createEntityRecordApi,\n updateEntityRecordApi,\n deleteEntityRecordApi,\n countEntityRecordsApi,\n bulkCreateEntityRecordsApi,\n bulkUpdateEntityRecordsApi,\n bulkDeleteEntityRecordsApi,\n} from \"../api\";\nimport { useApiAsync } from \"./use-async\";\nimport { useOptionsRef } from \"./use-options-ref\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport interface UseEntityRecordsOptions extends ApiClientOptions {\n /** Entity name to operate on */\n entityName: string;\n}\n\nexport interface QueryRecordsParams {\n page?: number;\n pageSize?: number;\n filters?: Record<string, unknown>;\n sortBy?: string;\n sortOrder?: \"asc\" | \"desc\";\n}\n\nexport interface QueryRecordsResult {\n records: EntityRecord[];\n total: number;\n page: number;\n pageSize: number;\n}\n\nexport interface BulkOperationResult {\n records?: EntityRecord[];\n success: boolean;\n}\n\n// =============================================================================\n// USE ENTITY RECORDS HOOK\n// =============================================================================\n\n/**\n * Hook for entity record CRUD operations\n *\n * @example\n * ```tsx\n * const {\n * loading, error,\n * queryRecords, getRecord, createRecord, updateRecord, deleteRecord,\n * countRecords, bulkCreate, bulkUpdate, bulkDelete\n * } = useEntityRecords({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * entityName: \"contacts\",\n * });\n *\n * const { records, total } = await queryRecords({ page: 1, pageSize: 20 });\n * const record = await getRecord(\"record-id\");\n * const count = await countRecords({ status: \"active\" });\n * ```\n */\nexport function useEntityRecords(options: UseEntityRecordsOptions) {\n const optionsRef = useOptionsRef(options);\n\n const getEntityName = () => optionsRef.current.entityName;\n const getApiOptions = (): ApiClientOptions => {\n const { entityName: _, ...apiOptions } = optionsRef.current;\n return apiOptions;\n };\n\n const { execute: queryRecords, loading: queryLoading, error: queryError } = useApiAsync(\n (params?: QueryRecordsParams) => {\n const queryParams: Record<string, unknown> = {\n page: params?.page || 1,\n pageSize: params?.pageSize || 20,\n };\n if (params?.filters) {\n queryParams.filters = JSON.stringify(params.filters);\n }\n if (params?.sortBy) {\n queryParams.sortBy = params.sortBy;\n }\n if (params?.sortOrder) {\n queryParams.sortOrder = params.sortOrder;\n }\n return queryEntityRecordsApi(getEntityName(), queryParams, getApiOptions());\n },\n (data): QueryRecordsResult => {\n // Handle both direct records array and nested ListResult structure\n if (data?.records?.items) {\n return {\n records: data.records.items,\n total: data.records.totalCount,\n page: data.records.currentPage,\n pageSize: data.records.pageSize,\n };\n }\n // Fallback for simpler response structure\n return {\n records: (data as any)?.records || [],\n total: (data as any)?.total || 0,\n page: (data as any)?.page || 1,\n pageSize: (data as any)?.pageSize || 20,\n };\n },\n { records: [], total: 0, page: 1, pageSize: 20 } as QueryRecordsResult\n );\n\n const { execute: getRecord, loading: getLoading, error: getError } = useApiAsync(\n (recordId: string) => getEntityRecordApi(getEntityName(), recordId, getApiOptions()),\n (data) => data.record || null,\n null as EntityRecord | null\n );\n\n const { execute: createRecord, loading: createLoading, error: createError } = useApiAsync(\n (record: Partial<EntityRecord>) => createEntityRecordApi(getEntityName(), record, getApiOptions()),\n (data) => data.record || null,\n null as EntityRecord | null\n );\n\n const { execute: updateRecord, loading: updateLoading, error: updateError } = useApiAsync(\n (recordId: string, record: Partial<EntityRecord>) =>\n updateEntityRecordApi(getEntityName(), recordId, record, getApiOptions()),\n (data) => data.record || null,\n null as EntityRecord | null\n );\n\n const { execute: deleteRecord, loading: deleteLoading, error: deleteError } = useApiAsync(\n (recordId: string) => deleteEntityRecordApi(getEntityName(), recordId, getApiOptions()),\n (data) => data.success,\n false\n );\n\n const { execute: countRecords, loading: countLoading, error: countError } = useApiAsync(\n (filters?: Record<string, unknown>) =>\n countEntityRecordsApi(getEntityName(), filters || {}, getApiOptions()),\n (data) => data.count,\n 0\n );\n\n const { execute: bulkCreate, loading: bulkCreateLoading, error: bulkCreateError } = useApiAsync(\n (records: Partial<EntityRecord>[]) =>\n bulkCreateEntityRecordsApi(getEntityName(), records, getApiOptions()),\n (data): BulkOperationResult => ({ records: data.records, success: true }),\n { success: false } as BulkOperationResult\n );\n\n const { execute: bulkUpdate, loading: bulkUpdateLoading, error: bulkUpdateError } = useApiAsync(\n (records: Partial<EntityRecord>[]) =>\n bulkUpdateEntityRecordsApi(getEntityName(), records, getApiOptions()),\n (data): BulkOperationResult => ({ records: data.records, success: true }),\n { success: false } as BulkOperationResult\n );\n\n const { execute: bulkDelete, loading: bulkDeleteLoading, error: bulkDeleteError } = useApiAsync(\n (recordIds: string[]) =>\n bulkDeleteEntityRecordsApi(getEntityName(), recordIds, getApiOptions()),\n (data) => data.success,\n false\n );\n\n const loading =\n queryLoading || getLoading || createLoading || updateLoading || deleteLoading ||\n countLoading || bulkCreateLoading || bulkUpdateLoading || bulkDeleteLoading;\n\n const error =\n queryError || getError || createError || updateError || deleteError ||\n countError || bulkCreateError || bulkUpdateError || bulkDeleteError;\n\n return useMemo(\n () => ({\n loading,\n error,\n queryRecords,\n getRecord,\n createRecord,\n updateRecord,\n deleteRecord,\n countRecords,\n bulkCreate,\n bulkUpdate,\n bulkDelete,\n }),\n [\n loading, error,\n queryRecords, getRecord, createRecord, updateRecord, deleteRecord,\n countRecords, bulkCreate, bulkUpdate, bulkDelete,\n ]\n );\n}\n","\"use client\";\n\n/**\n * Entity hooks for React applications\n *\n * Provides React hooks for entity CRUD operations with loading/error states.\n */\n\nimport { useState, useCallback } from \"react\";\nimport type { ApiClientOptions } from \"@elqnt/api-client\";\nimport type { EntityDefinition, EntityRecord } from \"../models\";\nimport {\n listEntityDefinitionsApi,\n getEntityDefinitionApi,\n queryEntityRecordsApi,\n getEntityRecordApi,\n createEntityRecordApi,\n updateEntityRecordApi,\n deleteEntityRecordApi,\n} from \"../api\";\n\n// =============================================================================\n// TYPES\n// =============================================================================\n\nexport type UseEntitiesOptions = ApiClientOptions;\n\nexport interface QueryOptions {\n page?: number;\n pageSize?: number;\n filters?: Record<string, unknown>;\n sortBy?: string;\n sortOrder?: \"asc\" | \"desc\";\n}\n\nexport interface QueryResult {\n records: EntityRecord[];\n total: number;\n page: number;\n pageSize: number;\n}\n\n// =============================================================================\n// USE ENTITIES HOOK\n// =============================================================================\n\n/**\n * Hook for entity CRUD operations\n *\n * @example\n * ```tsx\n * const { loading, error, queryRecords, createRecord } = useEntities({\n * baseUrl: apiGatewayUrl,\n * orgId: selectedOrgId,\n * userId: user?.id,\n * userEmail: user?.email,\n * });\n *\n * const records = await queryRecords(\"contacts\", { page: 1, pageSize: 20 });\n * ```\n */\nexport function useEntities(options: UseEntitiesOptions) {\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<string | null>(null);\n\n const listDefinitions = useCallback(async (): Promise<EntityDefinition[]> => {\n setLoading(true);\n setError(null);\n try {\n const response = await listEntityDefinitionsApi(options);\n if (response.error) {\n setError(response.error);\n return [];\n }\n return response.data?.definitions || [];\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to load definitions\";\n setError(message);\n return [];\n } finally {\n setLoading(false);\n }\n }, [options]);\n\n const getDefinition = useCallback(\n async (entityName: string): Promise<EntityDefinition | null> => {\n setLoading(true);\n setError(null);\n try {\n const response = await getEntityDefinitionApi(entityName, options);\n if (response.error) {\n setError(response.error);\n return null;\n }\n return response.data?.definition || null;\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to get definition\";\n setError(message);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [options]\n );\n\n const queryRecords = useCallback(\n async (entityName: string, query: QueryOptions = {}): Promise<QueryResult> => {\n setLoading(true);\n setError(null);\n try {\n const queryParams: Record<string, unknown> = {\n page: query.page || 1,\n pageSize: query.pageSize || 20,\n };\n if (query.filters) {\n queryParams.filters = JSON.stringify(query.filters);\n }\n if (query.sortBy) {\n queryParams.sortBy = query.sortBy;\n }\n if (query.sortOrder) {\n queryParams.sortOrder = query.sortOrder;\n }\n\n const response = await queryEntityRecordsApi(entityName, queryParams, options);\n if (response.error) {\n setError(response.error);\n return { records: [], total: 0, page: 1, pageSize: 20 };\n }\n\n // Handle both direct records array and nested ListResult structure\n const data = response.data;\n if (data?.records?.items) {\n // ListEntityRecordsResponse with ListResult\n return {\n records: data.records.items,\n total: data.records.totalCount,\n page: data.records.currentPage,\n pageSize: data.records.pageSize,\n };\n }\n // Fallback for simpler response structure\n return {\n records: (data as any)?.records || [],\n total: (data as any)?.total || 0,\n page: (data as any)?.page || 1,\n pageSize: (data as any)?.pageSize || 20,\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to query records\";\n setError(message);\n return { records: [], total: 0, page: 1, pageSize: 20 };\n } finally {\n setLoading(false);\n }\n },\n [options]\n );\n\n const getRecord = useCallback(\n async (entityName: string, recordId: string): Promise<EntityRecord | null> => {\n setLoading(true);\n setError(null);\n try {\n const response = await getEntityRecordApi(entityName, recordId, options);\n if (response.error) {\n setError(response.error);\n return null;\n }\n return response.data?.record || null;\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to get record\";\n setError(message);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [options]\n );\n\n const createRecord = useCallback(\n async (entityName: string, record: Partial<EntityRecord>): Promise<EntityRecord | null> => {\n setLoading(true);\n setError(null);\n try {\n const response = await createEntityRecordApi(entityName, record, options);\n if (response.error) {\n setError(response.error);\n return null;\n }\n return response.data?.record || null;\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to create record\";\n setError(message);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [options]\n );\n\n const updateRecord = useCallback(\n async (\n entityName: string,\n recordId: string,\n record: Partial<EntityRecord>\n ): Promise<EntityRecord | null> => {\n setLoading(true);\n setError(null);\n try {\n const response = await updateEntityRecordApi(entityName, recordId, record, options);\n if (response.error) {\n setError(response.error);\n return null;\n }\n return response.data?.record || null;\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to update record\";\n setError(message);\n return null;\n } finally {\n setLoading(false);\n }\n },\n [options]\n );\n\n const deleteRecord = useCallback(\n async (entityName: string, recordId: string): Promise<boolean> => {\n setLoading(true);\n setError(null);\n try {\n const response = await deleteEntityRecordApi(entityName, recordId, options);\n if (response.error) {\n setError(response.error);\n return false;\n }\n return true;\n } catch (err) {\n const message = err instanceof Error ? err.message : \"Failed to delete record\";\n setError(message);\n return false;\n } finally {\n setLoading(false);\n }\n },\n [options]\n );\n\n return {\n loading,\n error,\n listDefinitions,\n getDefinition,\n queryRecords,\n getRecord,\n createRecord,\n updateRecord,\n deleteRecord,\n };\n}\n"]}
|