@elqnt/entity 2.1.0 → 2.1.2

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 ADDED
@@ -0,0 +1,210 @@
1
+ # @elqnt/entity
2
+
3
+ Complete entity management for Eloquent platform - models, API, hooks, and store.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @elqnt/entity
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ Create app-specific hooks that wrap `useEntities` internally:
14
+
15
+ ```tsx
16
+ // hooks/use-contacts.ts
17
+ import { useEntities } from "@elqnt/entity/hooks";
18
+ import type { EntityRecord } from "@elqnt/entity/models";
19
+ import { useAppConfig } from "@/app/providers";
20
+
21
+ // App-specific model (camelCase)
22
+ interface Contact {
23
+ id: string;
24
+ name: string;
25
+ email: string;
26
+ company?: string;
27
+ }
28
+
29
+ // Transform EntityRecord → App model
30
+ function toContact(record: EntityRecord): Contact {
31
+ return {
32
+ id: record.id,
33
+ name: record.fields.name,
34
+ email: record.fields.email,
35
+ company: record.fields.company,
36
+ };
37
+ }
38
+
39
+ export function useContacts() {
40
+ const config = useAppConfig();
41
+ const { queryRecords, getRecord, createRecord, updateRecord, deleteRecord, loading, error } = useEntities({
42
+ baseUrl: config.apiGatewayUrl,
43
+ orgId: config.orgId,
44
+ });
45
+
46
+ const fetchContacts = async (filters?: Record<string, unknown>) => {
47
+ const result = await queryRecords("contact", { filters });
48
+ return result?.records?.map(toContact) ?? [];
49
+ };
50
+
51
+ const getContact = async (id: string) => {
52
+ const record = await getRecord("contact", id);
53
+ return record ? toContact(record) : null;
54
+ };
55
+
56
+ const createContact = async (data: Omit<Contact, "id">) => {
57
+ const record = await createRecord("contact", { fields: data });
58
+ return record ? toContact(record) : null;
59
+ };
60
+
61
+ const updateContact = async (id: string, data: Partial<Contact>) => {
62
+ const record = await updateRecord("contact", id, { fields: data });
63
+ return record ? toContact(record) : null;
64
+ };
65
+
66
+ return { fetchContacts, getContact, createContact, updateContact, deleteContact: deleteRecord, loading, error };
67
+ }
68
+ ```
69
+
70
+ Usage in components:
71
+
72
+ ```tsx
73
+ // components/contact-list.tsx
74
+ function ContactList() {
75
+ const { fetchContacts, loading, error } = useContacts();
76
+ const [contacts, setContacts] = useState<Contact[]>([]);
77
+
78
+ useEffect(() => {
79
+ fetchContacts({ status: "active" }).then(setContacts);
80
+ }, []);
81
+
82
+ if (loading) return <Spinner />;
83
+ if (error) return <Error message={error} />;
84
+ return <List items={contacts} />;
85
+ }
86
+ ```
87
+
88
+ ## Recommended Pattern
89
+
90
+ ```
91
+ @elqnt/entity/hooks (useEntities)
92
+
93
+ App-specific hook (useContacts, useTickets, etc.)
94
+
95
+ React Component
96
+ ```
97
+
98
+ **Key points:**
99
+ - `useEntities` handles loading states, error handling, and authentication
100
+ - App hooks transform `EntityRecord` → domain models (camelCase)
101
+ - Components consume app hooks, not `useEntities` directly
102
+
103
+ ## Exports
104
+
105
+ ### `/hooks` - React Hooks
106
+
107
+ | Hook | Description |
108
+ |------|-------------|
109
+ | `useEntities(options)` | Full CRUD operations with loading/error states |
110
+
111
+ Use `useEntities` inside your app-specific hooks (not directly in components):
112
+
113
+ ```tsx
114
+ // Inside your custom hook
115
+ import { useEntities } from "@elqnt/entity/hooks";
116
+
117
+ export function useMyEntities() {
118
+ const {
119
+ queryRecords, // Query multiple records with filters/pagination
120
+ getRecord, // Get single record by ID
121
+ createRecord, // Create new record
122
+ updateRecord, // Update existing record
123
+ deleteRecord, // Delete record
124
+ listDefinitions,// List entity definitions
125
+ getDefinition, // Get entity definition by name
126
+ loading, // Loading state
127
+ error, // Error message
128
+ } = useEntities({ baseUrl, orgId });
129
+
130
+ // Transform and expose domain-specific functions
131
+ // ...
132
+ }
133
+ ```
134
+
135
+ ### `/api` - API Functions
136
+
137
+ Low-level API functions for direct HTTP calls.
138
+
139
+ ```tsx
140
+ import {
141
+ // Entity Definitions
142
+ listEntityDefinitionsApi,
143
+ getEntityDefinitionApi,
144
+ createEntityDefinitionApi,
145
+ updateEntityDefinitionApi,
146
+ deleteEntityDefinitionApi,
147
+
148
+ // Entity Records
149
+ queryEntityRecordsApi,
150
+ getEntityRecordApi,
151
+ createEntityRecordApi,
152
+ updateEntityRecordApi,
153
+ deleteEntityRecordApi,
154
+
155
+ // Bulk Operations
156
+ bulkCreateEntityRecordsApi,
157
+ bulkUpdateEntityRecordsApi,
158
+ bulkDeleteEntityRecordsApi,
159
+
160
+ // Count
161
+ countEntityRecordsApi,
162
+ } from "@elqnt/entity/api";
163
+ ```
164
+
165
+ ### `/models` - TypeScript Types
166
+
167
+ Types generated from Go via tygo.
168
+
169
+ ```tsx
170
+ import type {
171
+ EntityDefinition,
172
+ EntityRecord,
173
+ EntityQuery,
174
+ Filter,
175
+ Sort,
176
+ ListEntityRecordsResponse,
177
+ GetEntityRecordResponse,
178
+ } from "@elqnt/entity/models";
179
+ ```
180
+
181
+ ### Main Entry Point
182
+
183
+ You can also import everything from the main entry:
184
+
185
+ ```tsx
186
+ import { useEntities, EntityRecord, queryEntityRecordsApi } from "@elqnt/entity";
187
+ ```
188
+
189
+ ## Options
190
+
191
+ ```tsx
192
+ interface UseEntitiesOptions {
193
+ baseUrl: string; // API Gateway URL
194
+ orgId: string; // Organization ID
195
+ userId?: string; // Optional user ID for headers
196
+ userEmail?: string; // Optional user email for headers
197
+ }
198
+ ```
199
+
200
+ ## Query Options
201
+
202
+ ```tsx
203
+ interface QueryOptions {
204
+ page?: number; // Page number (default: 1)
205
+ pageSize?: number; // Items per page (default: 20)
206
+ filters?: Record<string, unknown>; // Filter conditions
207
+ sortBy?: string; // Field to sort by
208
+ sortOrder?: "asc" | "desc"; // Sort direction
209
+ }
210
+ ```
@@ -9,7 +9,7 @@
9
9
 
10
10
  var _chunkSXBB42DJjs = require('./chunk-SXBB42DJ.js');
11
11
 
12
- // hooks/index.ts
12
+ // hooks/use-entities.ts
13
13
  var _react = require('react');
14
14
  function useEntities(options) {
15
15
  const [loading, setLoading] = _react.useState.call(void 0, false);
@@ -201,4 +201,4 @@ function useEntities(options) {
201
201
 
202
202
 
203
203
  exports.useEntities = useEntities;
204
- //# sourceMappingURL=chunk-FVMQRPOM.js.map
204
+ //# sourceMappingURL=chunk-GQJJP4YL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/eloquent-packages/eloquent-packages/packages/entity/dist/chunk-GQJJP4YL.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,C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ADhEA;AACA;AACE;AACF,kCAAC","file":"/home/runner/work/eloquent-packages/eloquent-packages/packages/entity/dist/chunk-GQJJP4YL.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"]}
@@ -9,7 +9,7 @@ import {
9
9
  updateEntityRecordApi
10
10
  } from "./chunk-UHASYUCH.mjs";
11
11
 
12
- // hooks/index.ts
12
+ // hooks/use-entities.ts
13
13
  import { useState, useCallback } from "react";
14
14
  function useEntities(options) {
15
15
  const [loading, setLoading] = useState(false);
@@ -201,4 +201,4 @@ function useEntities(options) {
201
201
  export {
202
202
  useEntities
203
203
  };
204
- //# sourceMappingURL=chunk-2ESVAJLT.mjs.map
204
+ //# sourceMappingURL=chunk-JEDTIUWW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../hooks/use-entities.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,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AAU,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,OACE,YACA,UACA,WACiC;AACjC,iBAAW,IAAI;AACf,eAAS,IAAI;AACb,UAAI;AACF,cAAM,WAAW,MAAM,sBAAsB,YAAY,UAAU,QAAQ,OAAO;AAClF,YAAI,SAAS,OAAO;AAClB,mBAAS,SAAS,KAAK;AACvB,iBAAO;AAAA,QACT;AACA,eAAO,SAAS,MAAM,UAAU;AAAA,MAClC,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,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":[]}
@@ -1,5 +1,5 @@
1
1
  import { ApiClientOptions } from '@elqnt/api-client';
2
- import { EntityRecord, EntityDefinition } from '../models/index.mjs';
2
+ import { EntityDefinition, EntityRecord } from '../models/index.mjs';
3
3
  import '@elqnt/types';
4
4
 
5
5
  type UseEntitiesOptions = ApiClientOptions;
@@ -1,5 +1,5 @@
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
3
  import '@elqnt/types';
4
4
 
5
5
  type UseEntitiesOptions = ApiClientOptions;
@@ -2,9 +2,9 @@
2
2
  "use client";
3
3
 
4
4
 
5
- var _chunkFVMQRPOMjs = require('../chunk-FVMQRPOM.js');
5
+ var _chunkGQJJP4YLjs = require('../chunk-GQJJP4YL.js');
6
6
  require('../chunk-SXBB42DJ.js');
7
7
 
8
8
 
9
- exports.useEntities = _chunkFVMQRPOMjs.useEntities;
9
+ exports.useEntities = _chunkGQJJP4YLjs.useEntities;
10
10
  //# sourceMappingURL=index.js.map
@@ -2,7 +2,7 @@
2
2
  "use client";
3
3
  import {
4
4
  useEntities
5
- } from "../chunk-2ESVAJLT.mjs";
5
+ } from "../chunk-JEDTIUWW.mjs";
6
6
  import "../chunk-UHASYUCH.mjs";
7
7
  export {
8
8
  useEntities
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 _chunkFVMQRPOMjs = require('./chunk-FVMQRPOM.js');
4
+ var _chunkGQJJP4YLjs = require('./chunk-GQJJP4YL.js');
5
5
 
6
6
 
7
7
 
@@ -392,5 +392,5 @@ var PREDEFINED_COLORS = [
392
392
 
393
393
 
394
394
 
395
- exports.EntityDefinitionCreate = _chunk4GC36G4Djs.EntityDefinitionCreate; exports.EntityDefinitionCreated = _chunk4GC36G4Djs.EntityDefinitionCreated; exports.EntityDefinitionDelete = _chunk4GC36G4Djs.EntityDefinitionDelete; exports.EntityDefinitionDeleted = _chunk4GC36G4Djs.EntityDefinitionDeleted; exports.EntityDefinitionGet = _chunk4GC36G4Djs.EntityDefinitionGet; exports.EntityDefinitionGetServer = _chunk4GC36G4Djs.EntityDefinitionGetServer; exports.EntityDefinitionList = _chunk4GC36G4Djs.EntityDefinitionList; exports.EntityDefinitionUpdate = _chunk4GC36G4Djs.EntityDefinitionUpdate; exports.EntityDefinitionUpdated = _chunk4GC36G4Djs.EntityDefinitionUpdated; exports.EntityFieldTypeBool = _chunk4GC36G4Djs.EntityFieldTypeBool; exports.EntityFieldTypeCurrency = _chunk4GC36G4Djs.EntityFieldTypeCurrency; exports.EntityFieldTypeDate = _chunk4GC36G4Djs.EntityFieldTypeDate; exports.EntityFieldTypeDateTime = _chunk4GC36G4Djs.EntityFieldTypeDateTime; exports.EntityFieldTypeDropdown = _chunk4GC36G4Djs.EntityFieldTypeDropdown; exports.EntityFieldTypeEmail = _chunk4GC36G4Djs.EntityFieldTypeEmail; exports.EntityFieldTypeFile = _chunk4GC36G4Djs.EntityFieldTypeFile; exports.EntityFieldTypeFloat = _chunk4GC36G4Djs.EntityFieldTypeFloat; exports.EntityFieldTypeImage = _chunk4GC36G4Djs.EntityFieldTypeImage; exports.EntityFieldTypeInt = _chunk4GC36G4Djs.EntityFieldTypeInt; exports.EntityFieldTypeJSON = _chunk4GC36G4Djs.EntityFieldTypeJSON; exports.EntityFieldTypeLookup = _chunk4GC36G4Djs.EntityFieldTypeLookup; exports.EntityFieldTypeMultiLookup = _chunk4GC36G4Djs.EntityFieldTypeMultiLookup; exports.EntityFieldTypeMultiSelect = _chunk4GC36G4Djs.EntityFieldTypeMultiSelect; exports.EntityFieldTypePhone = _chunk4GC36G4Djs.EntityFieldTypePhone; exports.EntityFieldTypeString = _chunk4GC36G4Djs.EntityFieldTypeString; exports.EntityFieldTypeStringMultiline = _chunk4GC36G4Djs.EntityFieldTypeStringMultiline; exports.EntityFieldTypeText = _chunk4GC36G4Djs.EntityFieldTypeText; exports.EntityFieldTypeURL = _chunk4GC36G4Djs.EntityFieldTypeURL; exports.EntityFieldTypes = _chunk4GC36G4Djs.EntityFieldTypes; exports.EntityFilterOperators = _chunk4GC36G4Djs.EntityFilterOperators; exports.EntityOrgSchemaCreate = _chunk4GC36G4Djs.EntityOrgSchemaCreate; exports.EntityOrgSchemaDrop = _chunk4GC36G4Djs.EntityOrgSchemaDrop; exports.EntityRecordCount = _chunk4GC36G4Djs.EntityRecordCount; exports.EntityRecordCreate = _chunk4GC36G4Djs.EntityRecordCreate; exports.EntityRecordCreated = _chunk4GC36G4Djs.EntityRecordCreated; exports.EntityRecordDelete = _chunk4GC36G4Djs.EntityRecordDelete; exports.EntityRecordDeleted = _chunk4GC36G4Djs.EntityRecordDeleted; exports.EntityRecordGet = _chunk4GC36G4Djs.EntityRecordGet; exports.EntityRecordQuery = _chunk4GC36G4Djs.EntityRecordQuery; exports.EntityRecordUpdate = _chunk4GC36G4Djs.EntityRecordUpdate; exports.EntityRecordUpdated = _chunk4GC36G4Djs.EntityRecordUpdated; exports.EntityRecordsBulkCreate = _chunk4GC36G4Djs.EntityRecordsBulkCreate; exports.EntityRecordsBulkCreated = _chunk4GC36G4Djs.EntityRecordsBulkCreated; exports.EntityRecordsBulkDelete = _chunk4GC36G4Djs.EntityRecordsBulkDelete; exports.EntityRecordsBulkDeleted = _chunk4GC36G4Djs.EntityRecordsBulkDeleted; exports.EntityRecordsBulkUpdate = _chunk4GC36G4Djs.EntityRecordsBulkUpdate; exports.EntityRecordsBulkUpdated = _chunk4GC36G4Djs.EntityRecordsBulkUpdated; exports.EntityViewCreate = _chunk4GC36G4Djs.EntityViewCreate; exports.EntityViewCreated = _chunk4GC36G4Djs.EntityViewCreated; exports.EntityViewDelete = _chunk4GC36G4Djs.EntityViewDelete; exports.EntityViewDeleted = _chunk4GC36G4Djs.EntityViewDeleted; exports.EntityViewList = _chunk4GC36G4Djs.EntityViewList; exports.EntityViewUpdate = _chunk4GC36G4Djs.EntityViewUpdate; exports.EntityViewUpdated = _chunk4GC36G4Djs.EntityViewUpdated; exports.OperatorBetween = _chunk4GC36G4Djs.OperatorBetween; exports.OperatorContains = _chunk4GC36G4Djs.OperatorContains; exports.OperatorEmpty = _chunk4GC36G4Djs.OperatorEmpty; exports.OperatorEndsWith = _chunk4GC36G4Djs.OperatorEndsWith; exports.OperatorEq = _chunk4GC36G4Djs.OperatorEq; exports.OperatorExists = _chunk4GC36G4Djs.OperatorExists; exports.OperatorGt = _chunk4GC36G4Djs.OperatorGt; exports.OperatorGte = _chunk4GC36G4Djs.OperatorGte; exports.OperatorIn = _chunk4GC36G4Djs.OperatorIn; exports.OperatorLt = _chunk4GC36G4Djs.OperatorLt; exports.OperatorLte = _chunk4GC36G4Djs.OperatorLte; exports.OperatorNe = _chunk4GC36G4Djs.OperatorNe; exports.OperatorNin = _chunk4GC36G4Djs.OperatorNin; exports.OperatorStartsWith = _chunk4GC36G4Djs.OperatorStartsWith; exports.PREDEFINED_COLORS = PREDEFINED_COLORS; exports.RecordChangeActionCreated = _chunk4GC36G4Djs.RecordChangeActionCreated; exports.RecordChangeActionDeleted = _chunk4GC36G4Djs.RecordChangeActionDeleted; exports.RecordChangeActionUpdated = _chunk4GC36G4Djs.RecordChangeActionUpdated; 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.entityDefinitionReducer = entityDefinitionReducer; exports.entityRecordReducer = entityRecordReducer; exports.getEntityDefinitionApi = _chunkSXBB42DJjs.getEntityDefinitionApi; exports.getEntityRecordApi = _chunkSXBB42DJjs.getEntityRecordApi; exports.listEntityDefinitionsApi = _chunkSXBB42DJjs.listEntityDefinitionsApi; exports.queryEntityRecordsApi = _chunkSXBB42DJjs.queryEntityRecordsApi; exports.updateEntityDefinitionApi = _chunkSXBB42DJjs.updateEntityDefinitionApi; exports.updateEntityRecordApi = _chunkSXBB42DJjs.updateEntityRecordApi; exports.useEntities = _chunkFVMQRPOMjs.useEntities;
395
+ exports.EntityDefinitionCreate = _chunk4GC36G4Djs.EntityDefinitionCreate; exports.EntityDefinitionCreated = _chunk4GC36G4Djs.EntityDefinitionCreated; exports.EntityDefinitionDelete = _chunk4GC36G4Djs.EntityDefinitionDelete; exports.EntityDefinitionDeleted = _chunk4GC36G4Djs.EntityDefinitionDeleted; exports.EntityDefinitionGet = _chunk4GC36G4Djs.EntityDefinitionGet; exports.EntityDefinitionGetServer = _chunk4GC36G4Djs.EntityDefinitionGetServer; exports.EntityDefinitionList = _chunk4GC36G4Djs.EntityDefinitionList; exports.EntityDefinitionUpdate = _chunk4GC36G4Djs.EntityDefinitionUpdate; exports.EntityDefinitionUpdated = _chunk4GC36G4Djs.EntityDefinitionUpdated; exports.EntityFieldTypeBool = _chunk4GC36G4Djs.EntityFieldTypeBool; exports.EntityFieldTypeCurrency = _chunk4GC36G4Djs.EntityFieldTypeCurrency; exports.EntityFieldTypeDate = _chunk4GC36G4Djs.EntityFieldTypeDate; exports.EntityFieldTypeDateTime = _chunk4GC36G4Djs.EntityFieldTypeDateTime; exports.EntityFieldTypeDropdown = _chunk4GC36G4Djs.EntityFieldTypeDropdown; exports.EntityFieldTypeEmail = _chunk4GC36G4Djs.EntityFieldTypeEmail; exports.EntityFieldTypeFile = _chunk4GC36G4Djs.EntityFieldTypeFile; exports.EntityFieldTypeFloat = _chunk4GC36G4Djs.EntityFieldTypeFloat; exports.EntityFieldTypeImage = _chunk4GC36G4Djs.EntityFieldTypeImage; exports.EntityFieldTypeInt = _chunk4GC36G4Djs.EntityFieldTypeInt; exports.EntityFieldTypeJSON = _chunk4GC36G4Djs.EntityFieldTypeJSON; exports.EntityFieldTypeLookup = _chunk4GC36G4Djs.EntityFieldTypeLookup; exports.EntityFieldTypeMultiLookup = _chunk4GC36G4Djs.EntityFieldTypeMultiLookup; exports.EntityFieldTypeMultiSelect = _chunk4GC36G4Djs.EntityFieldTypeMultiSelect; exports.EntityFieldTypePhone = _chunk4GC36G4Djs.EntityFieldTypePhone; exports.EntityFieldTypeString = _chunk4GC36G4Djs.EntityFieldTypeString; exports.EntityFieldTypeStringMultiline = _chunk4GC36G4Djs.EntityFieldTypeStringMultiline; exports.EntityFieldTypeText = _chunk4GC36G4Djs.EntityFieldTypeText; exports.EntityFieldTypeURL = _chunk4GC36G4Djs.EntityFieldTypeURL; exports.EntityFieldTypes = _chunk4GC36G4Djs.EntityFieldTypes; exports.EntityFilterOperators = _chunk4GC36G4Djs.EntityFilterOperators; exports.EntityOrgSchemaCreate = _chunk4GC36G4Djs.EntityOrgSchemaCreate; exports.EntityOrgSchemaDrop = _chunk4GC36G4Djs.EntityOrgSchemaDrop; exports.EntityRecordCount = _chunk4GC36G4Djs.EntityRecordCount; exports.EntityRecordCreate = _chunk4GC36G4Djs.EntityRecordCreate; exports.EntityRecordCreated = _chunk4GC36G4Djs.EntityRecordCreated; exports.EntityRecordDelete = _chunk4GC36G4Djs.EntityRecordDelete; exports.EntityRecordDeleted = _chunk4GC36G4Djs.EntityRecordDeleted; exports.EntityRecordGet = _chunk4GC36G4Djs.EntityRecordGet; exports.EntityRecordQuery = _chunk4GC36G4Djs.EntityRecordQuery; exports.EntityRecordUpdate = _chunk4GC36G4Djs.EntityRecordUpdate; exports.EntityRecordUpdated = _chunk4GC36G4Djs.EntityRecordUpdated; exports.EntityRecordsBulkCreate = _chunk4GC36G4Djs.EntityRecordsBulkCreate; exports.EntityRecordsBulkCreated = _chunk4GC36G4Djs.EntityRecordsBulkCreated; exports.EntityRecordsBulkDelete = _chunk4GC36G4Djs.EntityRecordsBulkDelete; exports.EntityRecordsBulkDeleted = _chunk4GC36G4Djs.EntityRecordsBulkDeleted; exports.EntityRecordsBulkUpdate = _chunk4GC36G4Djs.EntityRecordsBulkUpdate; exports.EntityRecordsBulkUpdated = _chunk4GC36G4Djs.EntityRecordsBulkUpdated; exports.EntityViewCreate = _chunk4GC36G4Djs.EntityViewCreate; exports.EntityViewCreated = _chunk4GC36G4Djs.EntityViewCreated; exports.EntityViewDelete = _chunk4GC36G4Djs.EntityViewDelete; exports.EntityViewDeleted = _chunk4GC36G4Djs.EntityViewDeleted; exports.EntityViewList = _chunk4GC36G4Djs.EntityViewList; exports.EntityViewUpdate = _chunk4GC36G4Djs.EntityViewUpdate; exports.EntityViewUpdated = _chunk4GC36G4Djs.EntityViewUpdated; exports.OperatorBetween = _chunk4GC36G4Djs.OperatorBetween; exports.OperatorContains = _chunk4GC36G4Djs.OperatorContains; exports.OperatorEmpty = _chunk4GC36G4Djs.OperatorEmpty; exports.OperatorEndsWith = _chunk4GC36G4Djs.OperatorEndsWith; exports.OperatorEq = _chunk4GC36G4Djs.OperatorEq; exports.OperatorExists = _chunk4GC36G4Djs.OperatorExists; exports.OperatorGt = _chunk4GC36G4Djs.OperatorGt; exports.OperatorGte = _chunk4GC36G4Djs.OperatorGte; exports.OperatorIn = _chunk4GC36G4Djs.OperatorIn; exports.OperatorLt = _chunk4GC36G4Djs.OperatorLt; exports.OperatorLte = _chunk4GC36G4Djs.OperatorLte; exports.OperatorNe = _chunk4GC36G4Djs.OperatorNe; exports.OperatorNin = _chunk4GC36G4Djs.OperatorNin; exports.OperatorStartsWith = _chunk4GC36G4Djs.OperatorStartsWith; exports.PREDEFINED_COLORS = PREDEFINED_COLORS; exports.RecordChangeActionCreated = _chunk4GC36G4Djs.RecordChangeActionCreated; exports.RecordChangeActionDeleted = _chunk4GC36G4Djs.RecordChangeActionDeleted; exports.RecordChangeActionUpdated = _chunk4GC36G4Djs.RecordChangeActionUpdated; 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.entityDefinitionReducer = entityDefinitionReducer; exports.entityRecordReducer = entityRecordReducer; exports.getEntityDefinitionApi = _chunkSXBB42DJjs.getEntityDefinitionApi; exports.getEntityRecordApi = _chunkSXBB42DJjs.getEntityRecordApi; exports.listEntityDefinitionsApi = _chunkSXBB42DJjs.listEntityDefinitionsApi; exports.queryEntityRecordsApi = _chunkSXBB42DJjs.queryEntityRecordsApi; exports.updateEntityDefinitionApi = _chunkSXBB42DJjs.updateEntityDefinitionApi; exports.updateEntityRecordApi = _chunkSXBB42DJjs.updateEntityRecordApi; exports.useEntities = _chunkGQJJP4YLjs.useEntities;
396
396
  //# 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-2ESVAJLT.mjs";
4
+ } from "./chunk-JEDTIUWW.mjs";
5
5
  import {
6
6
  bulkCreateEntityRecordsApi,
7
7
  bulkDeleteEntityRecordsApi,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elqnt/entity",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
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",
@@ -1 +0,0 @@
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;AAEt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AO;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":[]}
@@ -1 +0,0 @@
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,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,MA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A,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"]}