@elqnt/entity 2.1.3 → 2.2.1

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.
@@ -1,46 +1,104 @@
1
1
  import { ApiClientOptions } from '@elqnt/api-client';
2
- import { EntityRecord, EntityDefinition } from '../models/index.js';
2
+ import { EntityDefinition, EntityRecord } from '../models/index.js';
3
+ export { Q as QueryOptions, a as QueryResult, U as UseEntitiesOptions, u as useEntities } from '../use-entities-CC3WhBDv.js';
4
+ export { UseAsyncOptions, UseAsyncReturn, useApiAsync, useAsync } from '@elqnt/api-client/hooks';
5
+ import * as react from 'react';
3
6
  import '@elqnt/types';
4
7
 
5
- type UseEntitiesOptions = ApiClientOptions;
6
- interface QueryOptions {
8
+ type UseEntityDefinitionsOptions = ApiClientOptions;
9
+ /**
10
+ * Hook for entity definition CRUD operations
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const { loading, error, listDefinitions, getDefinition, createDefinition } = useEntityDefinitions({
15
+ * baseUrl: apiGatewayUrl,
16
+ * orgId: selectedOrgId,
17
+ * });
18
+ *
19
+ * const definitions = await listDefinitions();
20
+ * const definition = await getDefinition("contacts");
21
+ * const newDef = await createDefinition({ name: "leads", title: "Leads" });
22
+ * ```
23
+ */
24
+ declare function useEntityDefinitions(options: UseEntityDefinitionsOptions): {
25
+ loading: boolean;
26
+ error: string | null;
27
+ listDefinitions: () => Promise<EntityDefinition[]>;
28
+ getDefinition: (entityName: string) => Promise<EntityDefinition | null>;
29
+ createDefinition: (definition: Partial<EntityDefinition>) => Promise<EntityDefinition | null>;
30
+ updateDefinition: (entityName: string, definition: Partial<EntityDefinition>) => Promise<EntityDefinition | null>;
31
+ deleteDefinition: (entityName: string) => Promise<boolean>;
32
+ };
33
+
34
+ interface UseEntityRecordsOptions extends ApiClientOptions {
35
+ /** Entity name to operate on */
36
+ entityName: string;
37
+ }
38
+ interface QueryRecordsParams {
7
39
  page?: number;
8
40
  pageSize?: number;
9
41
  filters?: Record<string, unknown>;
10
42
  sortBy?: string;
11
43
  sortOrder?: "asc" | "desc";
12
44
  }
13
- interface QueryResult {
45
+ interface QueryRecordsResult {
14
46
  records: EntityRecord[];
15
47
  total: number;
16
48
  page: number;
17
49
  pageSize: number;
18
50
  }
51
+ interface BulkOperationResult {
52
+ records?: EntityRecord[];
53
+ success: boolean;
54
+ }
19
55
  /**
20
- * Hook for entity CRUD operations
56
+ * Hook for entity record CRUD operations
21
57
  *
22
58
  * @example
23
59
  * ```tsx
24
- * const { loading, error, queryRecords, createRecord } = useEntities({
60
+ * const {
61
+ * loading, error,
62
+ * queryRecords, getRecord, createRecord, updateRecord, deleteRecord,
63
+ * countRecords, bulkCreate, bulkUpdate, bulkDelete
64
+ * } = useEntityRecords({
25
65
  * baseUrl: apiGatewayUrl,
26
66
  * orgId: selectedOrgId,
27
- * userId: user?.id,
28
- * userEmail: user?.email,
67
+ * entityName: "contacts",
29
68
  * });
30
69
  *
31
- * const records = await queryRecords("contacts", { page: 1, pageSize: 20 });
70
+ * const { records, total } = await queryRecords({ page: 1, pageSize: 20 });
71
+ * const record = await getRecord("record-id");
72
+ * const count = await countRecords({ status: "active" });
32
73
  * ```
33
74
  */
34
- declare function useEntities(options: UseEntitiesOptions): {
75
+ declare function useEntityRecords(options: UseEntityRecordsOptions): {
35
76
  loading: boolean;
36
77
  error: string | null;
37
- listDefinitions: () => Promise<EntityDefinition[]>;
38
- getDefinition: (entityName: string) => Promise<EntityDefinition | null>;
39
- queryRecords: (entityName: string, query?: QueryOptions) => Promise<QueryResult>;
40
- getRecord: (entityName: string, recordId: string) => Promise<EntityRecord | null>;
41
- createRecord: (entityName: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
42
- updateRecord: (entityName: string, recordId: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
43
- deleteRecord: (entityName: string, recordId: string) => Promise<boolean>;
78
+ queryRecords: (params?: QueryRecordsParams | undefined) => Promise<QueryRecordsResult>;
79
+ getRecord: (recordId: string) => Promise<EntityRecord | null>;
80
+ createRecord: (record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
81
+ updateRecord: (recordId: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
82
+ deleteRecord: (recordId: string) => Promise<boolean>;
83
+ countRecords: (filters?: Record<string, unknown> | undefined) => Promise<number>;
84
+ bulkCreate: (records: Partial<EntityRecord>[]) => Promise<BulkOperationResult>;
85
+ bulkUpdate: (records: Partial<EntityRecord>[]) => Promise<BulkOperationResult>;
86
+ bulkDelete: (recordIds: string[]) => Promise<boolean>;
44
87
  };
45
88
 
46
- export { type QueryOptions, type QueryResult, type UseEntitiesOptions, useEntities };
89
+ /**
90
+ * Hook that keeps options in a ref for stable callback access
91
+ *
92
+ * @example
93
+ * ```tsx
94
+ * const optionsRef = useOptionsRef({ baseUrl, orgId });
95
+ *
96
+ * const fetchData = useCallback(async () => {
97
+ * // Always accesses latest options without recreating callback
98
+ * await api.fetch(optionsRef.current);
99
+ * }, []); // No dependencies needed
100
+ * ```
101
+ */
102
+ declare function useOptionsRef<T>(options: T): react.RefObject<T>;
103
+
104
+ export { type BulkOperationResult, type QueryRecordsParams, type QueryRecordsResult, type UseEntityDefinitionsOptions, type UseEntityRecordsOptions, useEntityDefinitions, useEntityRecords, useOptionsRef };
@@ -2,9 +2,19 @@
2
2
  "use client";
3
3
 
4
4
 
5
- var _chunkESJH4DJMjs = require('../chunk-ESJH4DJM.js');
5
+
6
+
7
+
8
+
9
+
10
+ var _chunkNKQEAJTPjs = require('../chunk-NKQEAJTP.js');
6
11
  require('../chunk-6SB5QDL5.js');
7
12
 
8
13
 
9
- exports.useEntities = _chunkESJH4DJMjs.useEntities;
14
+
15
+
16
+
17
+
18
+
19
+ exports.useApiAsync = _chunkNKQEAJTPjs.useApiAsync; exports.useAsync = _chunkNKQEAJTPjs.useAsync; exports.useEntities = _chunkNKQEAJTPjs.useEntities; exports.useEntityDefinitions = _chunkNKQEAJTPjs.useEntityDefinitions; exports.useEntityRecords = _chunkNKQEAJTPjs.useEntityRecords; exports.useOptionsRef = _chunkNKQEAJTPjs.useOptionsRef;
10
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/hooks/index.js"],"names":[],"mappings":"AAAA,qFAAY;AACZ,YAAY;AACZ;AACE;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,mDAAC","file":"/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/hooks/index.js"}
1
+ {"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/hooks/index.js"],"names":[],"mappings":"AAAA,qFAAY;AACZ,YAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,iVAAC","file":"/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/hooks/index.js"}
@@ -1,10 +1,20 @@
1
1
  "use client";
2
2
  "use client";
3
3
  import {
4
- useEntities
5
- } from "../chunk-OIVRV2UT.mjs";
4
+ useApiAsync,
5
+ useAsync,
6
+ useEntities,
7
+ useEntityDefinitions,
8
+ useEntityRecords,
9
+ useOptionsRef
10
+ } from "../chunk-WKCKDO3X.mjs";
6
11
  import "../chunk-SHMUKUYC.mjs";
7
12
  export {
8
- useEntities
13
+ useApiAsync,
14
+ useAsync,
15
+ useEntities,
16
+ useEntityDefinitions,
17
+ useEntityRecords,
18
+ useOptionsRef
9
19
  };
10
20
  //# sourceMappingURL=index.mjs.map
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EntityDefinition, EntityView, EntityRecord, EntityQuery, ListResult } from './models/index.mjs';
2
2
  export { EntityDefinitionResponse, EntityFilterOperatorTS, EntityRecordResponse, Filter, GetEntityRecordResponse, ListEntityDefinitionsResponse, ListEntityRecordsResponse, ResponseMetadata, Sort, ViewColumn, ViewFilter } from './models/index.mjs';
3
- export { QueryOptions, QueryResult, UseEntitiesOptions, useEntities } from './hooks/index.mjs';
3
+ export { Q as QueryOptions, a as QueryResult, U as UseEntitiesOptions, u as useEntities } from './use-entities-gK_B9I2n.mjs';
4
4
  export { bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi } from './api/index.mjs';
5
5
  import * as _reduxjs_toolkit from '@reduxjs/toolkit';
6
6
  import '@elqnt/types';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EntityDefinition, EntityView, EntityRecord, EntityQuery, ListResult } from './models/index.js';
2
2
  export { EntityDefinitionResponse, EntityFilterOperatorTS, EntityRecordResponse, Filter, GetEntityRecordResponse, ListEntityDefinitionsResponse, ListEntityRecordsResponse, ResponseMetadata, Sort, ViewColumn, ViewFilter } from './models/index.js';
3
- export { QueryOptions, QueryResult, UseEntitiesOptions, useEntities } from './hooks/index.js';
3
+ export { Q as QueryOptions, a as QueryResult, U as UseEntitiesOptions, u as useEntities } from './use-entities-CC3WhBDv.js';
4
4
  export { bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi } from './api/index.js';
5
5
  import * as _reduxjs_toolkit from '@reduxjs/toolkit';
6
6
  import '@elqnt/types';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
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
2
 
3
3
 
4
- var _chunkESJH4DJMjs = require('./chunk-ESJH4DJM.js');
4
+ var _chunkNKQEAJTPjs = require('./chunk-NKQEAJTP.js');
5
5
 
6
6
 
7
7
 
@@ -248,5 +248,5 @@ var PREDEFINED_COLORS = [
248
248
 
249
249
 
250
250
 
251
- exports.PREDEFINED_COLORS = PREDEFINED_COLORS; 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.entityDefinitionReducer = entityDefinitionReducer; exports.entityRecordReducer = entityRecordReducer; exports.getEntityDefinitionApi = _chunk6SB5QDL5js.getEntityDefinitionApi; exports.getEntityRecordApi = _chunk6SB5QDL5js.getEntityRecordApi; exports.listEntityDefinitionsApi = _chunk6SB5QDL5js.listEntityDefinitionsApi; exports.queryEntityRecordsApi = _chunk6SB5QDL5js.queryEntityRecordsApi; exports.updateEntityDefinitionApi = _chunk6SB5QDL5js.updateEntityDefinitionApi; exports.updateEntityRecordApi = _chunk6SB5QDL5js.updateEntityRecordApi; exports.useEntities = _chunkESJH4DJMjs.useEntities;
251
+ exports.PREDEFINED_COLORS = PREDEFINED_COLORS; 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.entityDefinitionReducer = entityDefinitionReducer; exports.entityRecordReducer = entityRecordReducer; exports.getEntityDefinitionApi = _chunk6SB5QDL5js.getEntityDefinitionApi; exports.getEntityRecordApi = _chunk6SB5QDL5js.getEntityRecordApi; exports.listEntityDefinitionsApi = _chunk6SB5QDL5js.listEntityDefinitionsApi; exports.queryEntityRecordsApi = _chunk6SB5QDL5js.queryEntityRecordsApi; exports.updateEntityDefinitionApi = _chunk6SB5QDL5js.updateEntityDefinitionApi; exports.updateEntityRecordApi = _chunk6SB5QDL5js.updateEntityRecordApi; exports.useEntities = _chunkNKQEAJTPjs.useEntities;
252
252
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import {
3
3
  useEntities
4
- } from "./chunk-OIVRV2UT.mjs";
4
+ } from "./chunk-WKCKDO3X.mjs";
5
5
  import {
6
6
  bulkCreateEntityRecordsApi,
7
7
  bulkDeleteEntityRecordsApi,
@@ -0,0 +1,45 @@
1
+ import { ApiClientOptions } from '@elqnt/api-client';
2
+ import { EntityRecord, EntityDefinition } from './models/index.js';
3
+
4
+ type UseEntitiesOptions = ApiClientOptions;
5
+ interface QueryOptions {
6
+ page?: number;
7
+ pageSize?: number;
8
+ filters?: Record<string, unknown>;
9
+ sortBy?: string;
10
+ sortOrder?: "asc" | "desc";
11
+ }
12
+ interface QueryResult {
13
+ records: EntityRecord[];
14
+ total: number;
15
+ page: number;
16
+ pageSize: number;
17
+ }
18
+ /**
19
+ * Hook for entity CRUD operations
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { loading, error, queryRecords, createRecord } = useEntities({
24
+ * baseUrl: apiGatewayUrl,
25
+ * orgId: selectedOrgId,
26
+ * userId: user?.id,
27
+ * userEmail: user?.email,
28
+ * });
29
+ *
30
+ * const records = await queryRecords("contacts", { page: 1, pageSize: 20 });
31
+ * ```
32
+ */
33
+ declare function useEntities(options: UseEntitiesOptions): {
34
+ loading: boolean;
35
+ error: string | null;
36
+ listDefinitions: () => Promise<EntityDefinition[]>;
37
+ getDefinition: (entityName: string) => Promise<EntityDefinition | null>;
38
+ queryRecords: (entityName: string, query?: QueryOptions) => Promise<QueryResult>;
39
+ getRecord: (entityName: string, recordId: string) => Promise<EntityRecord | null>;
40
+ createRecord: (entityName: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
41
+ updateRecord: (entityName: string, recordId: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
42
+ deleteRecord: (entityName: string, recordId: string) => Promise<boolean>;
43
+ };
44
+
45
+ export { type QueryOptions as Q, type UseEntitiesOptions as U, type QueryResult as a, useEntities as u };
@@ -0,0 +1,45 @@
1
+ import { ApiClientOptions } from '@elqnt/api-client';
2
+ import { EntityRecord, EntityDefinition } from './models/index.mjs';
3
+
4
+ type UseEntitiesOptions = ApiClientOptions;
5
+ interface QueryOptions {
6
+ page?: number;
7
+ pageSize?: number;
8
+ filters?: Record<string, unknown>;
9
+ sortBy?: string;
10
+ sortOrder?: "asc" | "desc";
11
+ }
12
+ interface QueryResult {
13
+ records: EntityRecord[];
14
+ total: number;
15
+ page: number;
16
+ pageSize: number;
17
+ }
18
+ /**
19
+ * Hook for entity CRUD operations
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { loading, error, queryRecords, createRecord } = useEntities({
24
+ * baseUrl: apiGatewayUrl,
25
+ * orgId: selectedOrgId,
26
+ * userId: user?.id,
27
+ * userEmail: user?.email,
28
+ * });
29
+ *
30
+ * const records = await queryRecords("contacts", { page: 1, pageSize: 20 });
31
+ * ```
32
+ */
33
+ declare function useEntities(options: UseEntitiesOptions): {
34
+ loading: boolean;
35
+ error: string | null;
36
+ listDefinitions: () => Promise<EntityDefinition[]>;
37
+ getDefinition: (entityName: string) => Promise<EntityDefinition | null>;
38
+ queryRecords: (entityName: string, query?: QueryOptions) => Promise<QueryResult>;
39
+ getRecord: (entityName: string, recordId: string) => Promise<EntityRecord | null>;
40
+ createRecord: (entityName: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
41
+ updateRecord: (entityName: string, recordId: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
42
+ deleteRecord: (entityName: string, recordId: string) => Promise<boolean>;
43
+ };
44
+
45
+ export { type QueryOptions as Q, type UseEntitiesOptions as U, type QueryResult as a, useEntities as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elqnt/entity",
3
- "version": "2.1.3",
3
+ "version": "2.2.1",
4
4
  "description": "Complete entity management for Eloquent platform - models, API, hooks, and store",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -36,8 +36,8 @@
36
36
  "directory": "packages/entity"
37
37
  },
38
38
  "dependencies": {
39
- "@elqnt/types": "2.0.9",
40
- "@elqnt/api-client": "1.0.3"
39
+ "@elqnt/types": "2.0.13",
40
+ "@elqnt/api-client": "1.0.5"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "@reduxjs/toolkit": "^2.0.0",
@@ -51,7 +51,7 @@
51
51
  "react-redux": "^9.1.2",
52
52
  "tsup": "^8.0.0",
53
53
  "typescript": "^5.0.0",
54
- "@elqnt/api-client": "1.0.3"
54
+ "@elqnt/api-client": "1.0.5"
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsup",
@@ -1,204 +0,0 @@
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
- var _chunk6SB5QDL5js = require('./chunk-6SB5QDL5.js');
11
-
12
- // hooks/use-entities.ts
13
- var _react = require('react');
14
- function useEntities(options) {
15
- const [loading, setLoading] = _react.useState.call(void 0, false);
16
- const [error, setError] = _react.useState.call(void 0, null);
17
- const listDefinitions = _react.useCallback.call(void 0, async () => {
18
- setLoading(true);
19
- setError(null);
20
- try {
21
- const response = await _chunk6SB5QDL5js.listEntityDefinitionsApi.call(void 0, options);
22
- if (response.error) {
23
- setError(response.error);
24
- return [];
25
- }
26
- return _optionalChain([response, 'access', _ => _.data, 'optionalAccess', _2 => _2.definitions]) || [];
27
- } catch (err) {
28
- const message = err instanceof Error ? err.message : "Failed to load definitions";
29
- setError(message);
30
- return [];
31
- } finally {
32
- setLoading(false);
33
- }
34
- }, [options]);
35
- const getDefinition = _react.useCallback.call(void 0,
36
- async (entityName) => {
37
- setLoading(true);
38
- setError(null);
39
- try {
40
- const response = await _chunk6SB5QDL5js.getEntityDefinitionApi.call(void 0, entityName, options);
41
- if (response.error) {
42
- setError(response.error);
43
- return null;
44
- }
45
- return _optionalChain([response, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.definition]) || null;
46
- } catch (err) {
47
- const message = err instanceof Error ? err.message : "Failed to get definition";
48
- setError(message);
49
- return null;
50
- } finally {
51
- setLoading(false);
52
- }
53
- },
54
- [options]
55
- );
56
- const queryRecords = _react.useCallback.call(void 0,
57
- async (entityName, query = {}) => {
58
- setLoading(true);
59
- setError(null);
60
- try {
61
- const queryParams = {
62
- page: query.page || 1,
63
- pageSize: query.pageSize || 20
64
- };
65
- if (query.filters) {
66
- queryParams.filters = JSON.stringify(query.filters);
67
- }
68
- if (query.sortBy) {
69
- queryParams.sortBy = query.sortBy;
70
- }
71
- if (query.sortOrder) {
72
- queryParams.sortOrder = query.sortOrder;
73
- }
74
- const response = await _chunk6SB5QDL5js.queryEntityRecordsApi.call(void 0, entityName, queryParams, options);
75
- if (response.error) {
76
- setError(response.error);
77
- return { records: [], total: 0, page: 1, pageSize: 20 };
78
- }
79
- const data = response.data;
80
- if (_optionalChain([data, 'optionalAccess', _5 => _5.records, 'optionalAccess', _6 => _6.items])) {
81
- return {
82
- records: data.records.items,
83
- total: data.records.totalCount,
84
- page: data.records.currentPage,
85
- pageSize: data.records.pageSize
86
- };
87
- }
88
- return {
89
- records: _optionalChain([data, 'optionalAccess', _7 => _7.records]) || [],
90
- total: _optionalChain([data, 'optionalAccess', _8 => _8.total]) || 0,
91
- page: _optionalChain([data, 'optionalAccess', _9 => _9.page]) || 1,
92
- pageSize: _optionalChain([data, 'optionalAccess', _10 => _10.pageSize]) || 20
93
- };
94
- } catch (err) {
95
- const message = err instanceof Error ? err.message : "Failed to query records";
96
- setError(message);
97
- return { records: [], total: 0, page: 1, pageSize: 20 };
98
- } finally {
99
- setLoading(false);
100
- }
101
- },
102
- [options]
103
- );
104
- const getRecord = _react.useCallback.call(void 0,
105
- async (entityName, recordId) => {
106
- setLoading(true);
107
- setError(null);
108
- try {
109
- const response = await _chunk6SB5QDL5js.getEntityRecordApi.call(void 0, entityName, recordId, options);
110
- if (response.error) {
111
- setError(response.error);
112
- return null;
113
- }
114
- return _optionalChain([response, 'access', _11 => _11.data, 'optionalAccess', _12 => _12.record]) || null;
115
- } catch (err) {
116
- const message = err instanceof Error ? err.message : "Failed to get record";
117
- setError(message);
118
- return null;
119
- } finally {
120
- setLoading(false);
121
- }
122
- },
123
- [options]
124
- );
125
- const createRecord = _react.useCallback.call(void 0,
126
- async (entityName, record) => {
127
- setLoading(true);
128
- setError(null);
129
- try {
130
- const response = await _chunk6SB5QDL5js.createEntityRecordApi.call(void 0, entityName, record, options);
131
- if (response.error) {
132
- setError(response.error);
133
- return null;
134
- }
135
- return _optionalChain([response, 'access', _13 => _13.data, 'optionalAccess', _14 => _14.record]) || null;
136
- } catch (err) {
137
- const message = err instanceof Error ? err.message : "Failed to create record";
138
- setError(message);
139
- return null;
140
- } finally {
141
- setLoading(false);
142
- }
143
- },
144
- [options]
145
- );
146
- const updateRecord = _react.useCallback.call(void 0,
147
- async (entityName, recordId, record) => {
148
- setLoading(true);
149
- setError(null);
150
- try {
151
- const response = await _chunk6SB5QDL5js.updateEntityRecordApi.call(void 0, entityName, recordId, record, options);
152
- if (response.error) {
153
- setError(response.error);
154
- return null;
155
- }
156
- return _optionalChain([response, 'access', _15 => _15.data, 'optionalAccess', _16 => _16.record]) || null;
157
- } catch (err) {
158
- const message = err instanceof Error ? err.message : "Failed to update record";
159
- setError(message);
160
- return null;
161
- } finally {
162
- setLoading(false);
163
- }
164
- },
165
- [options]
166
- );
167
- const deleteRecord = _react.useCallback.call(void 0,
168
- async (entityName, recordId) => {
169
- setLoading(true);
170
- setError(null);
171
- try {
172
- const response = await _chunk6SB5QDL5js.deleteEntityRecordApi.call(void 0, entityName, recordId, options);
173
- if (response.error) {
174
- setError(response.error);
175
- return false;
176
- }
177
- return true;
178
- } catch (err) {
179
- const message = err instanceof Error ? err.message : "Failed to delete record";
180
- setError(message);
181
- return false;
182
- } finally {
183
- setLoading(false);
184
- }
185
- },
186
- [options]
187
- );
188
- return {
189
- loading,
190
- error,
191
- listDefinitions,
192
- getDefinition,
193
- queryRecords,
194
- getRecord,
195
- createRecord,
196
- updateRecord,
197
- deleteRecord
198
- };
199
- }
200
-
201
-
202
-
203
- exports.useEntities = useEntities;
204
- //# sourceMappingURL=chunk-ESJH4DJM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/eloquent/eloquent/packages/@elqnt/entity/dist/chunk-ESJH4DJM.js","../hooks/use-entities.ts"],"names":[],"mappings":"AAAA,ylBAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACA;ACHA,8BAAsC;AAqD/B,SAAS,WAAA,CAAY,OAAA,EAA6B;AACvD,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,EAAA,EAAI,6BAAA,KAAc,CAAA;AAC5C,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,EAAA,EAAI,6BAAA,IAA4B,CAAA;AAEtD,EAAA,MAAM,gBAAA,EAAkB,gCAAA,MAAY,CAAA,EAAA,GAAyC;AAC3E,IAAA,UAAA,CAAW,IAAI,CAAA;AACf,IAAA,QAAA,CAAS,IAAI,CAAA;AACb,IAAA,IAAI;AACF,MAAA,MAAM,SAAA,EAAW,MAAM,uDAAA,OAAgC,CAAA;AACvD,MAAA,GAAA,CAAI,QAAA,CAAS,KAAA,EAAO;AAClB,QAAA,QAAA,CAAS,QAAA,CAAS,KAAK,CAAA;AACvB,QAAA,OAAO,CAAC,CAAA;AAAA,MACV;AACA,MAAA,uBAAO,QAAA,mBAAS,IAAA,6BAAM,cAAA,GAAe,CAAC,CAAA;AAAA,IACxC,EAAA,MAAA,CAAS,GAAA,EAAK;AACZ,MAAA,MAAM,QAAA,EAAU,IAAA,WAAe,MAAA,EAAQ,GAAA,CAAI,QAAA,EAAU,4BAAA;AACrD,MAAA,QAAA,CAAS,OAAO,CAAA;AAChB,MAAA,OAAO,CAAC,CAAA;AAAA,IACV,EAAA,QAAE;AACA,MAAA,UAAA,CAAW,KAAK,CAAA;AAAA,IAClB;AAAA,EACF,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,E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chunk-ESJH4DJM.js","sourcesContent":[null,"\"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"]}