@elqnt/entity 2.0.5 → 2.1.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.
@@ -0,0 +1,45 @@
1
+ import { ApiClientOptions, ApiResponse } from '@elqnt/api-client';
2
+ import { ResponseMetadata } from '@elqnt/types';
3
+ import { ListEntityDefinitionsResponse, EntityDefinitionResponse, EntityDefinition, ListEntityRecordsResponse, EntityRecordResponse, EntityRecord } from '../models/index.mjs';
4
+
5
+ /**
6
+ * Entity API functions
7
+ *
8
+ * Browser-side API client for entity operations.
9
+ * Uses @elqnt/api-client for HTTP requests with automatic token management.
10
+ */
11
+
12
+ declare function listEntityDefinitionsApi(options: ApiClientOptions): Promise<ApiResponse<ListEntityDefinitionsResponse>>;
13
+ declare function getEntityDefinitionApi(entityName: string, options: ApiClientOptions): Promise<ApiResponse<EntityDefinitionResponse>>;
14
+ declare function createEntityDefinitionApi(definition: Partial<EntityDefinition>, options: ApiClientOptions): Promise<ApiResponse<EntityDefinitionResponse>>;
15
+ declare function updateEntityDefinitionApi(entityName: string, definition: Partial<EntityDefinition>, options: ApiClientOptions): Promise<ApiResponse<EntityDefinitionResponse>>;
16
+ declare function deleteEntityDefinitionApi(entityName: string, options: ApiClientOptions): Promise<ApiResponse<{
17
+ success: boolean;
18
+ metadata: ResponseMetadata;
19
+ }>>;
20
+ declare function queryEntityRecordsApi(entityName: string, query: Record<string, unknown>, options: ApiClientOptions): Promise<ApiResponse<ListEntityRecordsResponse>>;
21
+ declare function getEntityRecordApi(entityName: string, recordId: string, options: ApiClientOptions): Promise<ApiResponse<EntityRecordResponse>>;
22
+ declare function createEntityRecordApi(entityName: string, record: Partial<EntityRecord>, options: ApiClientOptions): Promise<ApiResponse<EntityRecordResponse>>;
23
+ declare function updateEntityRecordApi(entityName: string, recordId: string, record: Partial<EntityRecord>, options: ApiClientOptions): Promise<ApiResponse<EntityRecordResponse>>;
24
+ declare function deleteEntityRecordApi(entityName: string, recordId: string, options: ApiClientOptions): Promise<ApiResponse<{
25
+ success: boolean;
26
+ metadata: ResponseMetadata;
27
+ }>>;
28
+ declare function bulkCreateEntityRecordsApi(entityName: string, records: Partial<EntityRecord>[], options: ApiClientOptions): Promise<ApiResponse<{
29
+ records: EntityRecord[];
30
+ metadata: ResponseMetadata;
31
+ }>>;
32
+ declare function bulkUpdateEntityRecordsApi(entityName: string, records: Partial<EntityRecord>[], options: ApiClientOptions): Promise<ApiResponse<{
33
+ records: EntityRecord[];
34
+ metadata: ResponseMetadata;
35
+ }>>;
36
+ declare function bulkDeleteEntityRecordsApi(entityName: string, recordIds: string[], options: ApiClientOptions): Promise<ApiResponse<{
37
+ success: boolean;
38
+ metadata: ResponseMetadata;
39
+ }>>;
40
+ declare function countEntityRecordsApi(entityName: string, filters: Record<string, unknown>, options: ApiClientOptions): Promise<ApiResponse<{
41
+ count: number;
42
+ metadata: ResponseMetadata;
43
+ }>>;
44
+
45
+ export { bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi };
@@ -0,0 +1,45 @@
1
+ import { ApiClientOptions, ApiResponse } from '@elqnt/api-client';
2
+ import { ResponseMetadata } from '@elqnt/types';
3
+ import { ListEntityDefinitionsResponse, EntityDefinitionResponse, EntityDefinition, ListEntityRecordsResponse, EntityRecordResponse, EntityRecord } from '../models/index.js';
4
+
5
+ /**
6
+ * Entity API functions
7
+ *
8
+ * Browser-side API client for entity operations.
9
+ * Uses @elqnt/api-client for HTTP requests with automatic token management.
10
+ */
11
+
12
+ declare function listEntityDefinitionsApi(options: ApiClientOptions): Promise<ApiResponse<ListEntityDefinitionsResponse>>;
13
+ declare function getEntityDefinitionApi(entityName: string, options: ApiClientOptions): Promise<ApiResponse<EntityDefinitionResponse>>;
14
+ declare function createEntityDefinitionApi(definition: Partial<EntityDefinition>, options: ApiClientOptions): Promise<ApiResponse<EntityDefinitionResponse>>;
15
+ declare function updateEntityDefinitionApi(entityName: string, definition: Partial<EntityDefinition>, options: ApiClientOptions): Promise<ApiResponse<EntityDefinitionResponse>>;
16
+ declare function deleteEntityDefinitionApi(entityName: string, options: ApiClientOptions): Promise<ApiResponse<{
17
+ success: boolean;
18
+ metadata: ResponseMetadata;
19
+ }>>;
20
+ declare function queryEntityRecordsApi(entityName: string, query: Record<string, unknown>, options: ApiClientOptions): Promise<ApiResponse<ListEntityRecordsResponse>>;
21
+ declare function getEntityRecordApi(entityName: string, recordId: string, options: ApiClientOptions): Promise<ApiResponse<EntityRecordResponse>>;
22
+ declare function createEntityRecordApi(entityName: string, record: Partial<EntityRecord>, options: ApiClientOptions): Promise<ApiResponse<EntityRecordResponse>>;
23
+ declare function updateEntityRecordApi(entityName: string, recordId: string, record: Partial<EntityRecord>, options: ApiClientOptions): Promise<ApiResponse<EntityRecordResponse>>;
24
+ declare function deleteEntityRecordApi(entityName: string, recordId: string, options: ApiClientOptions): Promise<ApiResponse<{
25
+ success: boolean;
26
+ metadata: ResponseMetadata;
27
+ }>>;
28
+ declare function bulkCreateEntityRecordsApi(entityName: string, records: Partial<EntityRecord>[], options: ApiClientOptions): Promise<ApiResponse<{
29
+ records: EntityRecord[];
30
+ metadata: ResponseMetadata;
31
+ }>>;
32
+ declare function bulkUpdateEntityRecordsApi(entityName: string, records: Partial<EntityRecord>[], options: ApiClientOptions): Promise<ApiResponse<{
33
+ records: EntityRecord[];
34
+ metadata: ResponseMetadata;
35
+ }>>;
36
+ declare function bulkDeleteEntityRecordsApi(entityName: string, recordIds: string[], options: ApiClientOptions): Promise<ApiResponse<{
37
+ success: boolean;
38
+ metadata: ResponseMetadata;
39
+ }>>;
40
+ declare function countEntityRecordsApi(entityName: string, filters: Record<string, unknown>, options: ApiClientOptions): Promise<ApiResponse<{
41
+ count: number;
42
+ metadata: ResponseMetadata;
43
+ }>>;
44
+
45
+ export { bulkCreateEntityRecordsApi, bulkDeleteEntityRecordsApi, bulkUpdateEntityRecordsApi, countEntityRecordsApi, createEntityDefinitionApi, createEntityRecordApi, deleteEntityDefinitionApi, deleteEntityRecordApi, getEntityDefinitionApi, getEntityRecordApi, listEntityDefinitionsApi, queryEntityRecordsApi, updateEntityDefinitionApi, updateEntityRecordApi };
@@ -0,0 +1,34 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ var _chunkSXBB42DJjs = require('../chunk-SXBB42DJ.js');
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ exports.bulkCreateEntityRecordsApi = _chunkSXBB42DJjs.bulkCreateEntityRecordsApi; exports.bulkDeleteEntityRecordsApi = _chunkSXBB42DJjs.bulkDeleteEntityRecordsApi; exports.bulkUpdateEntityRecordsApi = _chunkSXBB42DJjs.bulkUpdateEntityRecordsApi; exports.countEntityRecordsApi = _chunkSXBB42DJjs.countEntityRecordsApi; exports.createEntityDefinitionApi = _chunkSXBB42DJjs.createEntityDefinitionApi; exports.createEntityRecordApi = _chunkSXBB42DJjs.createEntityRecordApi; exports.deleteEntityDefinitionApi = _chunkSXBB42DJjs.deleteEntityDefinitionApi; exports.deleteEntityRecordApi = _chunkSXBB42DJjs.deleteEntityRecordApi; exports.getEntityDefinitionApi = _chunkSXBB42DJjs.getEntityDefinitionApi; exports.getEntityRecordApi = _chunkSXBB42DJjs.getEntityRecordApi; exports.listEntityDefinitionsApi = _chunkSXBB42DJjs.listEntityDefinitionsApi; exports.queryEntityRecordsApi = _chunkSXBB42DJjs.queryEntityRecordsApi; exports.updateEntityDefinitionApi = _chunkSXBB42DJjs.updateEntityDefinitionApi; exports.updateEntityRecordApi = _chunkSXBB42DJjs.updateEntityRecordApi;
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/eloquent-packages/eloquent-packages/packages/entity/dist/api/index.js"],"names":[],"mappings":"AAAA,qFAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uiCAAC","file":"/home/runner/work/eloquent-packages/eloquent-packages/packages/entity/dist/api/index.js"}
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import {
3
+ bulkCreateEntityRecordsApi,
4
+ bulkDeleteEntityRecordsApi,
5
+ bulkUpdateEntityRecordsApi,
6
+ countEntityRecordsApi,
7
+ createEntityDefinitionApi,
8
+ createEntityRecordApi,
9
+ deleteEntityDefinitionApi,
10
+ deleteEntityRecordApi,
11
+ getEntityDefinitionApi,
12
+ getEntityRecordApi,
13
+ listEntityDefinitionsApi,
14
+ queryEntityRecordsApi,
15
+ updateEntityDefinitionApi,
16
+ updateEntityRecordApi
17
+ } from "../chunk-UHASYUCH.mjs";
18
+ export {
19
+ bulkCreateEntityRecordsApi,
20
+ bulkDeleteEntityRecordsApi,
21
+ bulkUpdateEntityRecordsApi,
22
+ countEntityRecordsApi,
23
+ createEntityDefinitionApi,
24
+ createEntityRecordApi,
25
+ deleteEntityDefinitionApi,
26
+ deleteEntityRecordApi,
27
+ getEntityDefinitionApi,
28
+ getEntityRecordApi,
29
+ listEntityDefinitionsApi,
30
+ queryEntityRecordsApi,
31
+ updateEntityDefinitionApi,
32
+ updateEntityRecordApi
33
+ };
34
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,204 @@
1
+ "use client";
2
+ import {
3
+ createEntityRecordApi,
4
+ deleteEntityRecordApi,
5
+ getEntityDefinitionApi,
6
+ getEntityRecordApi,
7
+ listEntityDefinitionsApi,
8
+ queryEntityRecordsApi,
9
+ updateEntityRecordApi
10
+ } from "./chunk-UHASYUCH.mjs";
11
+
12
+ // hooks/index.ts
13
+ import { useState, useCallback } from "react";
14
+ function useEntities(options) {
15
+ const [loading, setLoading] = useState(false);
16
+ const [error, setError] = useState(null);
17
+ const listDefinitions = useCallback(async () => {
18
+ setLoading(true);
19
+ setError(null);
20
+ try {
21
+ const response = await listEntityDefinitionsApi(options);
22
+ if (response.error) {
23
+ setError(response.error);
24
+ return [];
25
+ }
26
+ return response.data?.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 = useCallback(
36
+ async (entityName) => {
37
+ setLoading(true);
38
+ setError(null);
39
+ try {
40
+ const response = await getEntityDefinitionApi(entityName, options);
41
+ if (response.error) {
42
+ setError(response.error);
43
+ return null;
44
+ }
45
+ return response.data?.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 = useCallback(
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 queryEntityRecordsApi(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 (data?.records?.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: data?.records || [],
90
+ total: data?.total || 0,
91
+ page: data?.page || 1,
92
+ pageSize: data?.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 = useCallback(
105
+ async (entityName, recordId) => {
106
+ setLoading(true);
107
+ setError(null);
108
+ try {
109
+ const response = await getEntityRecordApi(entityName, recordId, options);
110
+ if (response.error) {
111
+ setError(response.error);
112
+ return null;
113
+ }
114
+ return response.data?.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 = useCallback(
126
+ async (entityName, record) => {
127
+ setLoading(true);
128
+ setError(null);
129
+ try {
130
+ const response = await createEntityRecordApi(entityName, record, options);
131
+ if (response.error) {
132
+ setError(response.error);
133
+ return null;
134
+ }
135
+ return response.data?.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 = useCallback(
147
+ async (entityName, recordId, record) => {
148
+ setLoading(true);
149
+ setError(null);
150
+ try {
151
+ const response = await updateEntityRecordApi(entityName, recordId, record, options);
152
+ if (response.error) {
153
+ setError(response.error);
154
+ return null;
155
+ }
156
+ return response.data?.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 = useCallback(
168
+ async (entityName, recordId) => {
169
+ setLoading(true);
170
+ setError(null);
171
+ try {
172
+ const response = await deleteEntityRecordApi(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
+ export {
202
+ useEntities
203
+ };
204
+ //# sourceMappingURL=chunk-2ESVAJLT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../hooks/index.ts"],"sourcesContent":["\"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"],"mappings":";;;;;;;;;;;;AAQA,SAAS,UAAU,mBAAmB;AAqD/B,SAAS,YAAY,SAA6B;AACvD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AAEtD,QAAM,kBAAkB,YAAY,YAAyC;AAC3E,eAAW,IAAI;AACf,aAAS,IAAI;AACb,QAAI;AACF,YAAM,WAAW,MAAM,yBAAyB,OAAO;AACvD,UAAI,SAAS,OAAO;AAClB,iBAAS,SAAS,KAAK;AACvB,eAAO,CAAC;AAAA,MACV;AACA,aAAO,SAAS,MAAM,eAAe,CAAC;AAAA,IACxC,SAAS,KAAK;AACZ,YAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,eAAS,OAAO;AAChB,aAAO,CAAC;AAAA,IACV,UAAE;AACA,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,gBAAgB;AAAA,IACpB,OAAO,eAAyD;AAC9D,iBAAW,IAAI;AACf,eAAS,IAAI;AACb,UAAI;AACF,cAAM,WAAW,MAAM,uBAAuB,YAAY,OAAO;AACjE,YAAI,SAAS,OAAO;AAClB,mBAAS,SAAS,KAAK;AACvB,iBAAO;AAAA,QACT;AACA,eAAO,SAAS,MAAM,cAAc;AAAA,MACtC,SAAS,KAAK;AACZ,cAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,iBAAS,OAAO;AAChB,eAAO;AAAA,MACT,UAAE;AACA,mBAAW,KAAK;AAAA,MAClB;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,eAAe;AAAA,IACnB,OAAO,YAAoB,QAAsB,CAAC,MAA4B;AAC5E,iBAAW,IAAI;AACf,eAAS,IAAI;AAC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,OAAO,YAAoB,aAAuC;AAChE,iBAAW,IAAI;AACf,eAAS,IAAI;AACb,UAAI;AACF,cAAM,WAAW,MAAM,sBAAsB,YAAY,UAAU,OAAO;AAC1E,YAAI,SAAS,OAAO;AAClB,mBAAS,SAAS,KAAK;AACvB,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,cAAM,UAAU,eAAe,QAAQ,IAAI,UAAU;AACrD,iBAAS,OAAO;AAChB,eAAO;AAAA,MACT,UAAE;AACA,mBAAW,KAAK;AAAA,MAClB;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,204 @@
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 _chunkSXBB42DJjs = require('./chunk-SXBB42DJ.js');
11
+
12
+ // hooks/index.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 _chunkSXBB42DJjs.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 _chunkSXBB42DJjs.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 _chunkSXBB42DJjs.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 _chunkSXBB42DJjs.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 _chunkSXBB42DJjs.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 _chunkSXBB42DJjs.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 _chunkSXBB42DJjs.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-FVMQRPOM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/eloquent-packages/eloquent-packages/packages/entity/dist/chunk-FVMQRPOM.js","../hooks/index.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,I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A,CAAS,QAAA,CAAS,KAAK,CAAA;AACvB,UAAA,OAAO,KAAA;AAAA,QACT;AACA,QAAA,OAAO,IAAA;AAAA,MACT,EAAA,MAAA,CAAS,GAAA,EAAK;AACZ,QAAA,MAAM,QAAA,EAAU,IAAA,WAAe,MAAA,EAAQ,GAAA,CAAI,QAAA,EAAU,yBAAA;AACrD,QAAA,QAAA,CAAS,OAAO,CAAA;AAChB,QAAA,OAAO,KAAA;AAAA,MACT,EAAA,QAAE;AACA,QAAA,UAAA,CAAW,KAAK,CAAA;AAAA,MAClB;AAAA,IACF,CAAA;AAAA,IACA,CAAC,OAAO;AAAA,EACV,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,KAAA;AAAA,IACA,eAAA;AAAA,IACA,aAAA;AAAA,IACA,YAAA;AAAA,IACA,SAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF;ADhEA;AACA;AACE;AACF,kCAAC","file":"/home/runner/work/eloquent-packages/eloquent-packages/packages/entity/dist/chunk-FVMQRPOM.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"]}