@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/dist/hooks/index.d.ts
CHANGED
|
@@ -1,46 +1,141 @@
|
|
|
1
|
-
import { ApiClientOptions } from '@elqnt/api-client';
|
|
2
|
-
import {
|
|
1
|
+
import { ApiClientOptions, ApiResponse } from '@elqnt/api-client';
|
|
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
|
+
import * as react from 'react';
|
|
3
5
|
import '@elqnt/types';
|
|
4
6
|
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
+
type UseEntityDefinitionsOptions = ApiClientOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Hook for entity definition CRUD operations
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const { loading, error, listDefinitions, getDefinition, createDefinition } = useEntityDefinitions({
|
|
14
|
+
* baseUrl: apiGatewayUrl,
|
|
15
|
+
* orgId: selectedOrgId,
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const definitions = await listDefinitions();
|
|
19
|
+
* const definition = await getDefinition("contacts");
|
|
20
|
+
* const newDef = await createDefinition({ name: "leads", title: "Leads" });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function useEntityDefinitions(options: UseEntityDefinitionsOptions): {
|
|
24
|
+
loading: boolean;
|
|
25
|
+
error: string | null;
|
|
26
|
+
listDefinitions: () => Promise<EntityDefinition[]>;
|
|
27
|
+
getDefinition: (entityName: string) => Promise<EntityDefinition | null>;
|
|
28
|
+
createDefinition: (definition: Partial<EntityDefinition>) => Promise<EntityDefinition | null>;
|
|
29
|
+
updateDefinition: (entityName: string, definition: Partial<EntityDefinition>) => Promise<EntityDefinition | null>;
|
|
30
|
+
deleteDefinition: (entityName: string) => Promise<boolean>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
interface UseEntityRecordsOptions extends ApiClientOptions {
|
|
34
|
+
/** Entity name to operate on */
|
|
35
|
+
entityName: string;
|
|
36
|
+
}
|
|
37
|
+
interface QueryRecordsParams {
|
|
7
38
|
page?: number;
|
|
8
39
|
pageSize?: number;
|
|
9
40
|
filters?: Record<string, unknown>;
|
|
10
41
|
sortBy?: string;
|
|
11
42
|
sortOrder?: "asc" | "desc";
|
|
12
43
|
}
|
|
13
|
-
interface
|
|
44
|
+
interface QueryRecordsResult {
|
|
14
45
|
records: EntityRecord[];
|
|
15
46
|
total: number;
|
|
16
47
|
page: number;
|
|
17
48
|
pageSize: number;
|
|
18
49
|
}
|
|
50
|
+
interface BulkOperationResult {
|
|
51
|
+
records?: EntityRecord[];
|
|
52
|
+
success: boolean;
|
|
53
|
+
}
|
|
19
54
|
/**
|
|
20
|
-
* Hook for entity CRUD operations
|
|
55
|
+
* Hook for entity record CRUD operations
|
|
21
56
|
*
|
|
22
57
|
* @example
|
|
23
58
|
* ```tsx
|
|
24
|
-
* const {
|
|
59
|
+
* const {
|
|
60
|
+
* loading, error,
|
|
61
|
+
* queryRecords, getRecord, createRecord, updateRecord, deleteRecord,
|
|
62
|
+
* countRecords, bulkCreate, bulkUpdate, bulkDelete
|
|
63
|
+
* } = useEntityRecords({
|
|
25
64
|
* baseUrl: apiGatewayUrl,
|
|
26
65
|
* orgId: selectedOrgId,
|
|
27
|
-
*
|
|
28
|
-
* userEmail: user?.email,
|
|
66
|
+
* entityName: "contacts",
|
|
29
67
|
* });
|
|
30
68
|
*
|
|
31
|
-
* const records = await queryRecords(
|
|
69
|
+
* const { records, total } = await queryRecords({ page: 1, pageSize: 20 });
|
|
70
|
+
* const record = await getRecord("record-id");
|
|
71
|
+
* const count = await countRecords({ status: "active" });
|
|
32
72
|
* ```
|
|
33
73
|
*/
|
|
34
|
-
declare function
|
|
74
|
+
declare function useEntityRecords(options: UseEntityRecordsOptions): {
|
|
35
75
|
loading: boolean;
|
|
36
76
|
error: string | null;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
77
|
+
queryRecords: (params?: QueryRecordsParams | undefined) => Promise<QueryRecordsResult>;
|
|
78
|
+
getRecord: (recordId: string) => Promise<EntityRecord | null>;
|
|
79
|
+
createRecord: (record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
|
|
80
|
+
updateRecord: (recordId: string, record: Partial<EntityRecord>) => Promise<EntityRecord | null>;
|
|
81
|
+
deleteRecord: (recordId: string) => Promise<boolean>;
|
|
82
|
+
countRecords: (filters?: Record<string, unknown> | undefined) => Promise<number>;
|
|
83
|
+
bulkCreate: (records: Partial<EntityRecord>[]) => Promise<BulkOperationResult>;
|
|
84
|
+
bulkUpdate: (records: Partial<EntityRecord>[]) => Promise<BulkOperationResult>;
|
|
85
|
+
bulkDelete: (recordIds: string[]) => Promise<boolean>;
|
|
44
86
|
};
|
|
45
87
|
|
|
46
|
-
|
|
88
|
+
interface UseAsyncOptions {
|
|
89
|
+
/** Reset error on new request */
|
|
90
|
+
resetErrorOnRequest?: boolean;
|
|
91
|
+
}
|
|
92
|
+
interface UseAsyncReturn<TArgs extends unknown[], TResult> {
|
|
93
|
+
execute: (...args: TArgs) => Promise<TResult>;
|
|
94
|
+
loading: boolean;
|
|
95
|
+
error: string | null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Generic async operation hook with loading/error states
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* const { execute: fetchUser, loading, error } = useAsync(
|
|
103
|
+
* (userId: string) => getUserApi(userId, options),
|
|
104
|
+
* (data) => data.user,
|
|
105
|
+
* null
|
|
106
|
+
* );
|
|
107
|
+
*
|
|
108
|
+
* const user = await fetchUser("user-123");
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function useAsync<TArgs extends unknown[], TData, TResult>(asyncFn: (...args: TArgs) => Promise<ApiResponse<TData>>, transform: (data: TData) => TResult, defaultValue: TResult, options?: UseAsyncOptions): UseAsyncReturn<TArgs, TResult>;
|
|
112
|
+
/**
|
|
113
|
+
* Simplified async hook for API operations
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```tsx
|
|
117
|
+
* const { execute: getUsers, loading, error } = useApiAsync(
|
|
118
|
+
* () => listUsersApi(optionsRef.current),
|
|
119
|
+
* (data) => data.users,
|
|
120
|
+
* []
|
|
121
|
+
* );
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function useApiAsync<TArgs extends unknown[], TData, TResult>(asyncFn: (...args: TArgs) => Promise<ApiResponse<TData>>, transform: (data: TData) => TResult, defaultValue: TResult): UseAsyncReturn<TArgs, TResult>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Hook that keeps options in a ref for stable callback access
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```tsx
|
|
131
|
+
* const optionsRef = useOptionsRef({ baseUrl, orgId });
|
|
132
|
+
*
|
|
133
|
+
* const fetchData = useCallback(async () => {
|
|
134
|
+
* // Always accesses latest options without recreating callback
|
|
135
|
+
* await api.fetch(optionsRef.current);
|
|
136
|
+
* }, []); // No dependencies needed
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare function useOptionsRef<T>(options: T): react.RefObject<T>;
|
|
140
|
+
|
|
141
|
+
export { type BulkOperationResult, type QueryRecordsParams, type QueryRecordsResult, type UseAsyncOptions, type UseAsyncReturn, type UseEntityDefinitionsOptions, type UseEntityRecordsOptions, useApiAsync, useAsync, useEntityDefinitions, useEntityRecords, useOptionsRef };
|
package/dist/hooks/index.js
CHANGED
|
@@ -2,9 +2,19 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunk5BPHCJ2Gjs = require('../chunk-5BPHCJ2G.js');
|
|
6
11
|
require('../chunk-6SB5QDL5.js');
|
|
7
12
|
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.useApiAsync = _chunk5BPHCJ2Gjs.useApiAsync; exports.useAsync = _chunk5BPHCJ2Gjs.useAsync; exports.useEntities = _chunk5BPHCJ2Gjs.useEntities; exports.useEntityDefinitions = _chunk5BPHCJ2Gjs.useEntityDefinitions; exports.useEntityRecords = _chunk5BPHCJ2Gjs.useEntityRecords; exports.useOptionsRef = _chunk5BPHCJ2Gjs.useOptionsRef;
|
|
10
20
|
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/hooks/index.mjs
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
"use client";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
useApiAsync,
|
|
5
|
+
useAsync,
|
|
6
|
+
useEntities,
|
|
7
|
+
useEntityDefinitions,
|
|
8
|
+
useEntityRecords,
|
|
9
|
+
useOptionsRef
|
|
10
|
+
} from "../chunk-F7ZN7FHI.mjs";
|
|
6
11
|
import "../chunk-SHMUKUYC.mjs";
|
|
7
12
|
export {
|
|
8
|
-
|
|
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 './
|
|
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 './
|
|
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
|
|
4
|
+
var _chunk5BPHCJ2Gjs = require('./chunk-5BPHCJ2G.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 =
|
|
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 = _chunk5BPHCJ2Gjs.useEntities;
|
|
252
252
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "2.2.0",
|
|
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.
|
|
40
|
-
"@elqnt/api-client": "1.0.
|
|
39
|
+
"@elqnt/types": "2.0.13",
|
|
40
|
+
"@elqnt/api-client": "1.0.4"
|
|
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.
|
|
54
|
+
"@elqnt/api-client": "1.0.4"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"build": "tsup",
|
package/dist/chunk-ESJH4DJM.js
DELETED
|
@@ -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;AAE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/dist/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"]}
|