@mdxui/do 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +412 -0
- package/dist/__test-utils__/index.d.ts +399 -0
- package/dist/__test-utils__/index.js +34641 -0
- package/dist/__test-utils__/index.js.map +1 -0
- package/dist/agents-xcIn2dUB.d.ts +832 -0
- package/dist/chunk-EEDMN7UF.js +1351 -0
- package/dist/chunk-EEDMN7UF.js.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-GGO5GW72.js +695 -0
- package/dist/chunk-GGO5GW72.js.map +1 -0
- package/dist/chunk-GKSP5RIA.js +3 -0
- package/dist/chunk-GKSP5RIA.js.map +1 -0
- package/dist/chunk-NXPXL5NA.js +3789 -0
- package/dist/chunk-NXPXL5NA.js.map +1 -0
- package/dist/chunk-PC5FJY6M.js +20 -0
- package/dist/chunk-PC5FJY6M.js.map +1 -0
- package/dist/chunk-XF6LKY2M.js +445 -0
- package/dist/chunk-XF6LKY2M.js.map +1 -0
- package/dist/components/index.d.ts +813 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -0
- package/dist/do-CaQVueZw.d.ts +195 -0
- package/dist/hooks/index.d.ts +801 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +1012 -0
- package/dist/index.js +843 -0
- package/dist/index.js.map +1 -0
- package/dist/magic-string.es-J7BYFTTJ.js +1307 -0
- package/dist/magic-string.es-J7BYFTTJ.js.map +1 -0
- package/dist/providers/index.d.ts +90 -0
- package/dist/providers/index.js +5 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/schemas/index.d.ts +206 -0
- package/dist/schemas/index.js +262 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/thing-DtI25yZh.d.ts +902 -0
- package/dist/types/index.d.ts +7681 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +94 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1012 @@
|
|
|
1
|
+
export { AIModel, APIKey, APIKeyFilter, APIKeyPermissions, Address, AgentArtifactResponseSchema, AgentClassificationResponseSchema, AgentExecuteInputSchema, AgentExecutionFilterSchema, AgentExecutionResponse, AgentExecutionResponseSchema, AgentFeedbackInputSchema, AgentFeedbackResponseSchema, AgentFilterSchema, AgentGuardrailResponseSchema, AgentHandoffResponseSchema, AgentInputResponseSchema, AgentMetricsResponse, AgentMetricsResponseSchema, AgentOutputResponseSchema, AgentResponse, AgentResponseSchema, AgentTraceResponseSchema, AgentTypeResponseSchema, AgenticFunction, ApiKeyConfig, AppError, AuditEntry, AuthField, AuthenticationConfig, AuthenticationType, BaseError, BasicAuthConfig, BillingInfo, CellEditorProps, CellEditorType, CellRendererProps, CellValue, CharacterBibleResponseSchema, CodeFunction, ColumnEditorPanelProps, CompensationConfigResponseSchema, ConnectionFilter, ConnectionStatus, CustomAuthConfig, DBRecord, DOSQLResult, DOStorageInfo, DOStorageSchema, DataTypeCategory, DatabaseEditorProps, DatabaseGridProps, DatabaseSidebarProps, DatabaseToolbarProps, DateRangeFilter, DateResponseSchema, DeviceInfo, EditHistoryState, EditOperation, EntityReferenceResponseSchema, EntityReferenceSchema, EntityRelationshipsResultResponse, EntityRelationshipsResultResponseSchema, ErrorHandlingConfigResponseSchema, EscalationRule, EventDefinition, EventFilter, EventMetadata, EventQueryResult, EventReplayRequest, EventSource, EventStats, EventStream, EventSubscription, EventTimelineEntry, ExecutionContextResponseSchema, ExecutionErrorResponseSchema, ExecutionFilterSchema, FieldValidation, FilterSpec, ForeignKeyReference, Function, FunctionAgentClassification, FunctionAgentGuardrail, FunctionBase, FunctionCategory, FunctionExecution, FunctionExecutionStatus, FunctionFilter, FunctionHandoffRule, GenerativeFunction, GraphPath, GraphPathResponseSchema, GraphPattern, GraphPatternSchema, GraphStats, GraphStatsResponse, GraphStatsResponseSchema, GraphTraversalResult, GraphTraversalResultResponse, GraphTraversalResultResponseSchema, GuardrailViolationResponseSchema, HandoffRuleResponseSchema, HttpRequest, HttpResponse, HumanFunction, Integration, IntegrationAction, IntegrationCategory, IntegrationConnection, IntegrationError, IntegrationExecution, IntegrationField, IntegrationFilter, IntegrationSearch, IntegrationSource, IntegrationTrigger, InvitationStatus, MongoArrayOperators, MongoComparisonOperators, MongoElementOperators, MongoFieldOperators, MongoLogicalOperators, MongoProjection, MongoQuery, MongoSort, MongoStringOperators, MongoUpdateOperators, NotFoundError, NotificationPreferences, OAuth2Config, OperationEvent, OperationEventType, OptionalDateResponseSchema, Organization, OrganizationFilter, OrganizationInvitation, OrganizationMember, OrganizationMembership, OrganizationPlan, OrganizationRole, OrganizationSettings, OrganizationType, PaginatedResult, PaginatedResultResponseSchema, PaginationParams, PartialEntityReferenceSchema, PermissionError, PlanTier, PredicateDefinition, QueryStyle, RateLimitError, RecordMetadata, Relationship, RelationshipCreateInput, RelationshipCreateInputSchema, RelationshipEdge, RelationshipFilter, RelationshipFilterSchema, RelationshipMetadata, RelationshipMetadataResponseSchema, RelationshipMetadataSchema, RelationshipResponse, RelationshipResponseSchema, RelationshipsPanelProps, ReminderRule, ReplayTarget, ResourcePermission, RetryConfigResponseSchema, RowEditorPanelProps, SQLCondition, SQLEditorPanelProps, SQLOperator, SQLOrderBy, SQLWhereClause, SQLiteDataType, SQLiteStorageClass, SQLiteTypeAffinity, SSOConfig, SchemaOperation, SchemaVisualizerProps, SemanticEvent, SemanticId, SemanticIdComponents, SemanticPredicate, SemanticPredicateCategory, SemanticTriple, Session, SoftDeletable, SortParams, SortSpec, StepConfigResponseSchema, StepExecutionResponseSchema, SubscriptionStatus, TableAlterChanges, TableColumn, TableConstraint, TableDefinition, TableIndex, TableNode, TableTrigger, ThingCreateInputSchema, ThingDataSchema, ThingDeleteOptionsSchema, ThingFilterSchema, ThingPaginationSchema, ThingQueryResultResponse, ThingQueryResultResponseSchema, ThingResponse, ThingResponseSchema, ThingSortSchema, ThingUpdateInputSchema, ThingVersionResponse, ThingVersionResponseSchema, TokenUsageResponseSchema, ToolDefinition, TriggerDataResponseSchema, TypeStatsResponse, TypeStatsResponseSchema, UnifiedQuery, UsageLimits, UsageMetrics, UseEditHistoryReturn, User, UserFilter, UserPreferences, UserRole, ValidatedAgentExecutionFilter, ValidatedAgentFilter, ValidatedExecutionFilter, ValidatedRelationshipCreateInput, ValidatedRelationshipFilter, ValidatedThingCreateInput, ValidatedThingFilter, ValidatedThingUpdateInput, ValidatedWorkflowFilter, ValidationErrorData, WorkflowConfigResponseSchema, WorkflowExecutionResponse, WorkflowExecutionResponseSchema, WorkflowFilterSchema, WorkflowResponse, WorkflowResponseSchema, WorkflowStepResponseSchema, WorkflowTriggerInputSchema, WorkflowTriggerResponseSchema, isAppError, isNotFoundError, isPermissionError, isRateLimitError, isValidationErrorData } from './types/index.js';
|
|
2
|
+
export { DOContextValue, DOProvider, DOProviderProps, useDO, useDOUrls, useDataProviderSafe, useSyncStatus } from './providers/index.js';
|
|
3
|
+
export { BaseRecord, DO, DOAdminContextValue, DOProps, DeleteThingOptions, EntityRelationshipsData, ExecuteAgentInput, SubmitAgentFeedbackInput, UseAgentExecutionResult, UseAgentExecutionsResult, UseAgentMetricsResult, UseAgentResult, UseAgentsResult, UseCancelExecutionResult, UseCreateAgentResult, UseCreateRelationshipResult, UseCreateThingResult, UseCreateWorkflowResult, UseDOConfig, UseDOResult, UseDeleteAgentResult, UseDeleteRelationshipResult, UseDeleteThingResult, UseDeleteWorkflowResult, UseEntityRelationshipsResult, UseExecuteAgentResult, UseGraphStatsResult, UseGraphTraversalResult, UseRelationshipsResult, UseSubmitAgentFeedbackResult, UseThingResult, UseThingVersionsResult, UseThingsResult, UseTriggerWorkflowResult, UseTypeStatsResult, UseUpdateAgentResult, UseUpdateThingResult, UseUpdateWorkflowResult, UseWorkflowExecutionResult, UseWorkflowExecutionsResult, UseWorkflowResult, UseWorkflowsResult, agentsKeys, relationshipsKeys, thingsKeys, useAgent, useAgentExecution, useAgentExecutions, useAgentMetrics, useAgents, useCancelExecution, useCreateAgent, useCreateRelationship, useCreateThing, useCreateWorkflow, useDOAdmin, useDOContext, useDOResource, useDeleteAgent, useDeleteRelationship, useDeleteThing, useDeleteWorkflow, useEntityRelationships, useExecuteAgent, useGraphStats, useGraphTraversal, useIsDOEnabled, useRelationships, useSubmitAgentFeedback, useThing, useThingVersions, useThings, useTriggerWorkflow, useTypeStats, useUpdateAgent, useUpdateThing, useUpdateWorkflow, useWorkflow, useWorkflowExecution, useWorkflowExecutions, useWorkflows, workflowsKeys } from './hooks/index.js';
|
|
4
|
+
export { WorkflowContext, use$ } from '@dotdo/react';
|
|
5
|
+
export { AdminError, AdminErrorCode, AdminErrorDetails, CacheConfig, CreateParams, CreateResult, DataProvider, DataProviderConfig, DeleteManyParams, DeleteManyResult, DeleteParams, DeleteResult, AdminContextValue as DotdoAdminContextValue, AdminProvider as DotdoAdminProvider, DotdoDataProvider, DotdoDataProviderConfig, FilterOperator, GetListParams, GetListResult, GetManyParams, GetManyResult, GetOneParams, GetOneResult, InferredField, OptimisticConfig, QueryFilter, ResourceConfig, ResourceDefinition, SortOrder, UpdateParams, UpdateResult, createCacheKey, createResourceFromSchema, formatAdminError, inferFieldsFromSchema, invalidateCache, isAdminError, useAdminContext, useOptimisticUpdate } from '@dotdo/react/admin';
|
|
6
|
+
export { AgentExecutePanel, AgentExecutePanelProps, AgentFeedbackPanel, AgentFeedbackPanelProps, AgentHistoryTable, AgentHistoryTableProps, AgentsGrid, AgentsGridProps, ConfirmDialog, ConfirmDialogProps, DOErrorBoundary, DOErrorBoundaryProps, DOHeader, DOHeaderProps, DOShell, DOShellProps, DOSidebar, DOSidebarHeader, DOSidebarHeaderProps, DOSidebarProps, NavItem, StatCardData, StatsCards, StatsCardsProps, SyncIndicatorState, SyncStatusIndicator, SyncStatusIndicatorProps, ThingForm, ThingFormData, ThingFormDialog, ThingFormDialogProps, ThingFormErrors, ThingFormProps, ThingsList, ThingsListProps, ThingsPage, ThingsPageProps, Toast, ToastContainer, ToastContainerProps, ToastNotificationProps, ToastProvider, ToastProviderProps, ToastType, TriggerWorkflowDialog, TriggerWorkflowDialogProps, WorkflowExecutionView, WorkflowExecutionViewProps, WorkflowsList, WorkflowsListProps, defaultNavItems, defaultStats, useErrorBoundary, useShell, useToast } from './components/index.js';
|
|
7
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
|
+
import * as React from 'react';
|
|
9
|
+
import { ReactNode, ComponentType } from 'react';
|
|
10
|
+
import { GetListParams, GetListResult, GetOneParams, GetOneResult, GetManyParams, GetManyResult, CreateParams, CreateResult, UpdateParams, UpdateResult, DeleteParams, DeleteResult } from '@mdxui/app';
|
|
11
|
+
import { D as DOAdminConfig } from './do-CaQVueZw.js';
|
|
12
|
+
export { j as ConflictResolver, C as ConflictStrategy, d as DOAlarm, f as DOBinding, b as DOClassType, h as DOHealthCheck, c as DOInstance, i as DOMetrics, g as DORPCMethod, a as DOStatus, e as DOStorageEntry, O as OfflineConfig, S as SyncStatus } from './do-CaQVueZw.js';
|
|
13
|
+
import { d as ThingSort } from './thing-DtI25yZh.js';
|
|
14
|
+
export { N as Namespace, g as SemanticProperty, S as SemanticType, T as Thing, b as ThingCreateInput, f as ThingData, i as ThingDeleteOptions, c as ThingFilter, e as ThingPagination, a as ThingQueryResult, h as ThingUpdateInput, j as ThingVersion, k as TypeStats } from './thing-DtI25yZh.js';
|
|
15
|
+
import { ClassValue } from 'clsx';
|
|
16
|
+
export { EntityReference, ExecutionError, PaginatedResponse, Pagination, SortDirection, TokenUsage } from './schemas/index.js';
|
|
17
|
+
export { A as AIStepConfig, s as Agent, K as AgentArtifact, v as AgentClassification, F as AgentExecution, V as AgentExecutionFilter, G as AgentExecutionStatus, Q as AgentFeedback, U as AgentFilter, x as AgentGuardrail, O as AgentHandoff, I as AgentInput, B as AgentMetrics, J as AgentOutput, z as AgentStatus, L as AgentTrace, t as AgentType, w as CharacterBible, C as ChoiceCondition, j as CompensationConfig, D as DatabaseStepConfig, i as ErrorHandlingConfig, h as EventStepConfig, E as EventTrigger, o as ExecutionContext, r as ExecutionFilter, l as ExecutionStatus, P as GuardrailViolation, y as HandoffRule, H as HttpStepConfig, M as ManualTrigger, N as NotificationConfig, R as RetryConfig, u as RoleCategory, S as ScheduleTrigger, g as StepConfig, p as StepExecution, e as StepType, b as TriggerBase, n as TriggerData, T as TriggerType, c as WebhookTrigger, a as Workflow, k as WorkflowConfig, m as WorkflowExecution, q as WorkflowFilter, W as WorkflowStatus, f as WorkflowStep, d as WorkflowTrigger } from './agents-xcIn2dUB.js';
|
|
18
|
+
export { AdminProvider } from '@mdxui/admin/components';
|
|
19
|
+
import 'zod';
|
|
20
|
+
import '@tanstack/react-query';
|
|
21
|
+
import 'lucide-react';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Type Definitions for DoAdmin
|
|
25
|
+
*
|
|
26
|
+
* Types for the embedded admin interface in @mdxui/do.
|
|
27
|
+
* Provides pre-configured admin components for .do platform.
|
|
28
|
+
*
|
|
29
|
+
* @module @mdxui/do/admin
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Base record type with ID
|
|
34
|
+
*/
|
|
35
|
+
interface DoRecord {
|
|
36
|
+
id: string | number;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Extended DataProvider for DO-backed data operations.
|
|
41
|
+
* Adds DO-specific methods alongside standard CRUD operations.
|
|
42
|
+
*/
|
|
43
|
+
interface DoDataProvider {
|
|
44
|
+
getList: <T = DoRecord>(resource: string, params?: GetListParams) => Promise<GetListResult<T>>;
|
|
45
|
+
getOne: <T = DoRecord>(resource: string, params: GetOneParams) => Promise<GetOneResult<T>>;
|
|
46
|
+
getMany: <T = DoRecord>(resource: string, params: GetManyParams) => Promise<GetManyResult<T>>;
|
|
47
|
+
create: <T = DoRecord>(resource: string, params: CreateParams<T>) => Promise<CreateResult<T>>;
|
|
48
|
+
update: <T = DoRecord>(resource: string, params: UpdateParams<T>) => Promise<UpdateResult<T>>;
|
|
49
|
+
delete: <T = DoRecord>(resource: string, params: DeleteParams) => Promise<DeleteResult<T>>;
|
|
50
|
+
/**
|
|
51
|
+
* Get type statistics for a resource.
|
|
52
|
+
*/
|
|
53
|
+
getTypeStats?: (resource: string) => Promise<{
|
|
54
|
+
total: number;
|
|
55
|
+
recentlyCreated: number;
|
|
56
|
+
recentlyUpdated: number;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Get version history for a record.
|
|
60
|
+
*/
|
|
61
|
+
getVersions?: (resource: string, id: string) => Promise<unknown[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Restore a record to a previous version.
|
|
64
|
+
*/
|
|
65
|
+
restoreVersion?: (resource: string, id: string, version: number) => Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* User identity from DO auth context
|
|
69
|
+
*/
|
|
70
|
+
interface DoUserIdentity {
|
|
71
|
+
/** Unique user ID */
|
|
72
|
+
id: string;
|
|
73
|
+
/** User's full name */
|
|
74
|
+
fullName?: string;
|
|
75
|
+
/** User's email */
|
|
76
|
+
email?: string;
|
|
77
|
+
/** Avatar URL */
|
|
78
|
+
avatar?: string;
|
|
79
|
+
/** Namespace/tenant the user belongs to */
|
|
80
|
+
namespace?: string;
|
|
81
|
+
/** User's role */
|
|
82
|
+
role?: string;
|
|
83
|
+
/** Additional claims/attributes */
|
|
84
|
+
claims?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Login parameters for DO auth
|
|
88
|
+
*/
|
|
89
|
+
interface DoLoginParams {
|
|
90
|
+
/** Username or email */
|
|
91
|
+
username?: string;
|
|
92
|
+
/** Password */
|
|
93
|
+
password?: string;
|
|
94
|
+
/** API key (alternative to username/password) */
|
|
95
|
+
apiKey?: string;
|
|
96
|
+
/** OAuth token (for OAuth flows) */
|
|
97
|
+
oauthToken?: string;
|
|
98
|
+
/** Provider for OAuth (e.g., 'google', 'github') */
|
|
99
|
+
provider?: string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* DO Auth Provider interface
|
|
103
|
+
*/
|
|
104
|
+
interface DoAuthProvider {
|
|
105
|
+
/** Login with credentials */
|
|
106
|
+
login: (params: DoLoginParams) => Promise<void>;
|
|
107
|
+
/** Logout current session */
|
|
108
|
+
logout: () => Promise<void>;
|
|
109
|
+
/** Check if user is authenticated */
|
|
110
|
+
checkAuth: () => Promise<void>;
|
|
111
|
+
/** Check if an error is an auth error (401, 403) */
|
|
112
|
+
checkError: (error: Error) => Promise<void>;
|
|
113
|
+
/** Get current user identity */
|
|
114
|
+
getIdentity: () => Promise<DoUserIdentity>;
|
|
115
|
+
/** Get user permissions */
|
|
116
|
+
getPermissions: () => Promise<string[]>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resource definition for auto-generated CRUD views
|
|
120
|
+
*/
|
|
121
|
+
interface DoResourceDefinition {
|
|
122
|
+
/** Resource name (e.g., 'Task', 'User') */
|
|
123
|
+
name: string;
|
|
124
|
+
/** Display label (defaults to name) */
|
|
125
|
+
label?: string;
|
|
126
|
+
/** Icon component */
|
|
127
|
+
icon?: ReactNode;
|
|
128
|
+
/** Whether to show in sidebar */
|
|
129
|
+
showInSidebar?: boolean;
|
|
130
|
+
/** Custom list component (overrides auto-generated) */
|
|
131
|
+
list?: ComponentType;
|
|
132
|
+
/** Custom create component */
|
|
133
|
+
create?: ComponentType;
|
|
134
|
+
/** Custom edit component */
|
|
135
|
+
edit?: ComponentType;
|
|
136
|
+
/** Custom show component */
|
|
137
|
+
show?: ComponentType;
|
|
138
|
+
/** Field definitions for auto-generated views */
|
|
139
|
+
fields?: DoFieldDefinition[];
|
|
140
|
+
/** Filter definitions for list view */
|
|
141
|
+
filters?: DoFilterDefinition[];
|
|
142
|
+
/** Default sort for list view */
|
|
143
|
+
defaultSort?: ThingSort;
|
|
144
|
+
/** Records per page */
|
|
145
|
+
perPage?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Field definition for auto-generated forms and displays
|
|
149
|
+
*/
|
|
150
|
+
interface DoFieldDefinition {
|
|
151
|
+
/** Field name/key */
|
|
152
|
+
name: string;
|
|
153
|
+
/** Display label */
|
|
154
|
+
label?: string;
|
|
155
|
+
/** Field type (determines input/display component) */
|
|
156
|
+
type: DoFieldType;
|
|
157
|
+
/** Whether field is required */
|
|
158
|
+
required?: boolean;
|
|
159
|
+
/** Whether field is read-only */
|
|
160
|
+
readOnly?: boolean;
|
|
161
|
+
/** Whether to show in list view */
|
|
162
|
+
showInList?: boolean;
|
|
163
|
+
/** Whether to show in create/edit forms */
|
|
164
|
+
showInForm?: boolean;
|
|
165
|
+
/** Whether to show in detail view */
|
|
166
|
+
showInDetail?: boolean;
|
|
167
|
+
/** Column width in list view */
|
|
168
|
+
width?: number | string;
|
|
169
|
+
/** Reference resource (for reference fields) */
|
|
170
|
+
reference?: string;
|
|
171
|
+
/** Options for select fields */
|
|
172
|
+
choices?: Array<{
|
|
173
|
+
id: string | number;
|
|
174
|
+
name: string;
|
|
175
|
+
}>;
|
|
176
|
+
/** Validation rules */
|
|
177
|
+
validate?: DoValidationRule[];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Supported field types
|
|
181
|
+
*/
|
|
182
|
+
type DoFieldType = 'text' | 'number' | 'boolean' | 'date' | 'datetime' | 'email' | 'url' | 'password' | 'textarea' | 'richtext' | 'select' | 'reference' | 'array' | 'json' | 'image' | 'file';
|
|
183
|
+
/**
|
|
184
|
+
* Filter definition for list views
|
|
185
|
+
*/
|
|
186
|
+
interface DoFilterDefinition {
|
|
187
|
+
/** Field to filter on */
|
|
188
|
+
field: string;
|
|
189
|
+
/** Display label */
|
|
190
|
+
label?: string;
|
|
191
|
+
/** Filter type */
|
|
192
|
+
type: 'text' | 'select' | 'date' | 'daterange' | 'boolean' | 'number';
|
|
193
|
+
/** Options for select filter */
|
|
194
|
+
choices?: Array<{
|
|
195
|
+
id: string | number;
|
|
196
|
+
name: string;
|
|
197
|
+
}>;
|
|
198
|
+
/** Default value */
|
|
199
|
+
defaultValue?: unknown;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Validation rule
|
|
203
|
+
*/
|
|
204
|
+
interface DoValidationRule {
|
|
205
|
+
/** Rule type */
|
|
206
|
+
type: 'required' | 'email' | 'url' | 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'custom';
|
|
207
|
+
/** Value for the rule (e.g., min value, pattern) */
|
|
208
|
+
value?: unknown;
|
|
209
|
+
/** Error message */
|
|
210
|
+
message?: string;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Configuration for DoAdmin component
|
|
214
|
+
*/
|
|
215
|
+
interface DoAdminConfig {
|
|
216
|
+
/** Admin title */
|
|
217
|
+
title?: string;
|
|
218
|
+
/** Logo element */
|
|
219
|
+
logo?: ReactNode;
|
|
220
|
+
/** Theme preference */
|
|
221
|
+
theme?: 'light' | 'dark' | 'system';
|
|
222
|
+
/** Base path for admin routes */
|
|
223
|
+
basePath?: string;
|
|
224
|
+
/** DO configuration */
|
|
225
|
+
doConfig: DOAdminConfig;
|
|
226
|
+
/** Resource definitions */
|
|
227
|
+
resources?: DoResourceDefinition[];
|
|
228
|
+
/** Whether to auto-discover resources from DO schema */
|
|
229
|
+
autoDiscoverResources?: boolean;
|
|
230
|
+
/** Dashboard component */
|
|
231
|
+
dashboard?: ReactNode;
|
|
232
|
+
/** Login page component */
|
|
233
|
+
loginPage?: ReactNode;
|
|
234
|
+
/** 404 page component */
|
|
235
|
+
notFoundPage?: ReactNode;
|
|
236
|
+
/** Custom layout component */
|
|
237
|
+
layout?: ComponentType<{
|
|
238
|
+
children: ReactNode;
|
|
239
|
+
}>;
|
|
240
|
+
/** Sidebar footer content */
|
|
241
|
+
sidebarFooter?: ReactNode;
|
|
242
|
+
/** Whether to disable built-in router (for external router integration) */
|
|
243
|
+
disableRouter?: boolean;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Result type for useDoAdmin hook
|
|
247
|
+
*/
|
|
248
|
+
interface UseDoAdminResult {
|
|
249
|
+
/** Current user identity */
|
|
250
|
+
user: DoUserIdentity | null;
|
|
251
|
+
/** Whether user is authenticated */
|
|
252
|
+
isAuthenticated: boolean;
|
|
253
|
+
/** Whether auth is loading */
|
|
254
|
+
isAuthLoading: boolean;
|
|
255
|
+
/** Whether connected to DO backend */
|
|
256
|
+
isConnected: boolean;
|
|
257
|
+
/** Connection error if any */
|
|
258
|
+
connectionError: Error | null;
|
|
259
|
+
/** Available resources */
|
|
260
|
+
resources: DoResourceDefinition[];
|
|
261
|
+
/** Current namespace */
|
|
262
|
+
namespace: string;
|
|
263
|
+
/** Set namespace */
|
|
264
|
+
setNamespace: (ns: string) => void;
|
|
265
|
+
/** Login function - accepts any params with index signature */
|
|
266
|
+
login: (params: Record<string, unknown>) => Promise<void>;
|
|
267
|
+
/** Logout function */
|
|
268
|
+
logout: () => Promise<void>;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
interface DoAdminProps {
|
|
272
|
+
/** Admin configuration */
|
|
273
|
+
config: DoAdminConfig;
|
|
274
|
+
/** Children (additional content) */
|
|
275
|
+
children?: React.ReactNode;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* DoAdmin - Full-featured admin interface for .do platform
|
|
279
|
+
*
|
|
280
|
+
* Provides a complete admin dashboard with:
|
|
281
|
+
* - Pre-configured DO data provider
|
|
282
|
+
* - Pre-configured DO auth provider
|
|
283
|
+
* - Auto-generated CRUD views for resources
|
|
284
|
+
* - Sidebar navigation
|
|
285
|
+
* - User authentication
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```tsx
|
|
289
|
+
* import { DoAdmin } from '@mdxui/do'
|
|
290
|
+
*
|
|
291
|
+
* function App() {
|
|
292
|
+
* return (
|
|
293
|
+
* <DoAdmin
|
|
294
|
+
* config={{
|
|
295
|
+
* title: 'My Admin',
|
|
296
|
+
* doConfig: {
|
|
297
|
+
* apiEndpoint: 'https://api.example.do',
|
|
298
|
+
* authMethod: 'jwt',
|
|
299
|
+
* bindings: [],
|
|
300
|
+
* realTimeUpdates: true,
|
|
301
|
+
* },
|
|
302
|
+
* resources: [
|
|
303
|
+
* { name: 'Task', label: 'Tasks' },
|
|
304
|
+
* { name: 'User', label: 'Users' },
|
|
305
|
+
* ],
|
|
306
|
+
* }}
|
|
307
|
+
* />
|
|
308
|
+
* )
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```tsx
|
|
314
|
+
* // Minimal setup - auto-discovers resources
|
|
315
|
+
* <DoAdmin
|
|
316
|
+
* config={{
|
|
317
|
+
* doConfig: {
|
|
318
|
+
* apiEndpoint: 'https://api.example.do',
|
|
319
|
+
* authMethod: 'jwt',
|
|
320
|
+
* bindings: [],
|
|
321
|
+
* realTimeUpdates: true,
|
|
322
|
+
* },
|
|
323
|
+
* autoDiscoverResources: true,
|
|
324
|
+
* }}
|
|
325
|
+
* />
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
declare function DoAdmin({ config, children }: DoAdminProps): react_jsx_runtime.JSX.Element;
|
|
329
|
+
declare namespace DoAdmin {
|
|
330
|
+
var displayName: string;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* useDoAdmin - Hook to access DO admin context
|
|
334
|
+
*
|
|
335
|
+
* Provides access to user identity, auth state, resources, and namespace.
|
|
336
|
+
* Must be used within a DoAdmin component.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* ```tsx
|
|
340
|
+
* function MyComponent() {
|
|
341
|
+
* const {
|
|
342
|
+
* user,
|
|
343
|
+
* isAuthenticated,
|
|
344
|
+
* namespace,
|
|
345
|
+
* setNamespace,
|
|
346
|
+
* logout,
|
|
347
|
+
* } = useDoAdmin()
|
|
348
|
+
*
|
|
349
|
+
* return (
|
|
350
|
+
* <div>
|
|
351
|
+
* <p>Welcome, {user?.fullName}</p>
|
|
352
|
+
* <button onClick={logout}>Logout</button>
|
|
353
|
+
* </div>
|
|
354
|
+
* )
|
|
355
|
+
* }
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare function useDoAdmin(): UseDoAdminResult;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Resource Discovery Utility
|
|
362
|
+
*
|
|
363
|
+
* Auto-generates resource definitions from DO configuration.
|
|
364
|
+
* Used by DoAdmin to build navigation and CRUD views automatically.
|
|
365
|
+
*
|
|
366
|
+
* @module @mdxui/do/admin
|
|
367
|
+
*/
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Default resource types when no bindings or explicit resources are provided.
|
|
371
|
+
* These are the core entity types in the .do platform.
|
|
372
|
+
*/
|
|
373
|
+
declare const DEFAULT_RESOURCE_TYPES: readonly ["Thing", "Agent", "Workflow"];
|
|
374
|
+
/**
|
|
375
|
+
* Discover resources from configuration.
|
|
376
|
+
*
|
|
377
|
+
* Priority order:
|
|
378
|
+
* 1. Explicitly provided resources (config.resources)
|
|
379
|
+
* 2. Auto-discovered from bindings (if autoDiscoverResources is true)
|
|
380
|
+
* 3. Default resources (Thing, Agent, Workflow)
|
|
381
|
+
*
|
|
382
|
+
* @param config - DoAdmin configuration
|
|
383
|
+
* @returns Array of resource definitions
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```tsx
|
|
387
|
+
* // Explicit resources take priority
|
|
388
|
+
* const resources = discoverResources({
|
|
389
|
+
* doConfig: { ... },
|
|
390
|
+
* resources: [{ name: 'Task', label: 'Tasks' }],
|
|
391
|
+
* })
|
|
392
|
+
* // => [{ name: 'Task', label: 'Tasks' }]
|
|
393
|
+
*
|
|
394
|
+
* // Auto-discover from bindings
|
|
395
|
+
* const resources = discoverResources({
|
|
396
|
+
* doConfig: {
|
|
397
|
+
* bindings: [
|
|
398
|
+
* { name: 'THINGS', className: 'ThingsRelationshipsDO' },
|
|
399
|
+
* ],
|
|
400
|
+
* },
|
|
401
|
+
* autoDiscoverResources: true,
|
|
402
|
+
* })
|
|
403
|
+
* // => [{ name: 'Thing', label: 'Things', showInSidebar: true }]
|
|
404
|
+
*
|
|
405
|
+
* // Default resources when nothing specified
|
|
406
|
+
* const resources = discoverResources({
|
|
407
|
+
* doConfig: { bindings: [] },
|
|
408
|
+
* })
|
|
409
|
+
* // => [{ name: 'Thing', ... }, { name: 'Agent', ... }, { name: 'Workflow', ... }]
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
declare function discoverResources(config: DoAdminConfig): DoResourceDefinition[];
|
|
413
|
+
/**
|
|
414
|
+
* Merge discovered resources with explicit overrides.
|
|
415
|
+
*
|
|
416
|
+
* This allows users to provide partial resource definitions that override
|
|
417
|
+
* discovered defaults while keeping the auto-discovery behavior.
|
|
418
|
+
*
|
|
419
|
+
* @param discovered - Auto-discovered resources
|
|
420
|
+
* @param overrides - User-provided resource overrides (by name)
|
|
421
|
+
* @returns Merged resources with overrides applied
|
|
422
|
+
*/
|
|
423
|
+
declare function mergeResourceOverrides(discovered: DoResourceDefinition[], overrides: Partial<DoResourceDefinition>[]): DoResourceDefinition[];
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Create a DataProvider that uses DO Things API.
|
|
427
|
+
*
|
|
428
|
+
* This factory function creates a DataProvider implementation that:
|
|
429
|
+
* - Maps resources to DO Thing types
|
|
430
|
+
* - Translates CRUD operations to DO API calls
|
|
431
|
+
* - Supports both REST and RPC modes based on DOProvider config
|
|
432
|
+
*
|
|
433
|
+
* @param apiEndpoint - Base API endpoint
|
|
434
|
+
* @param authToken - Optional auth token
|
|
435
|
+
* @param namespace - Default namespace
|
|
436
|
+
* @param rpcUrl - RPC endpoint for TanStack DB mode
|
|
437
|
+
*/
|
|
438
|
+
declare function createDoDataProvider(apiEndpoint: string, authToken?: string, namespace?: string, rpcUrl?: string | null): DoDataProvider;
|
|
439
|
+
interface DoDataProviderProviderProps {
|
|
440
|
+
/** Children to render */
|
|
441
|
+
children: React.ReactNode;
|
|
442
|
+
/** Optional pre-created data provider */
|
|
443
|
+
dataProvider?: DoDataProvider;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* DoDataProviderProvider
|
|
447
|
+
*
|
|
448
|
+
* A provider component that automatically creates and provides a DO-backed
|
|
449
|
+
* DataProvider using the current DOProvider context.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```tsx
|
|
453
|
+
* <DOProvider config={doConfig}>
|
|
454
|
+
* <DoDataProviderProvider>
|
|
455
|
+
* <MyApp />
|
|
456
|
+
* </DoDataProviderProvider>
|
|
457
|
+
* </DOProvider>
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
declare function DoDataProviderProvider({ children, dataProvider: providedDataProvider, }: DoDataProviderProviderProps): react_jsx_runtime.JSX.Element;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Create an AuthProvider that uses DO authentication API.
|
|
464
|
+
*
|
|
465
|
+
* @param apiEndpoint - Base API endpoint
|
|
466
|
+
* @param authMethod - Authentication method (jwt, api-key, oauth)
|
|
467
|
+
* @param authToken - Optional pre-existing auth token
|
|
468
|
+
* @param namespace - Default namespace
|
|
469
|
+
*/
|
|
470
|
+
declare function createDoAuthProvider(apiEndpoint: string, authMethod: 'jwt' | 'api-key' | 'oauth', authToken?: string, namespace?: string): DoAuthProvider;
|
|
471
|
+
interface DoAuthProviderProviderProps {
|
|
472
|
+
/** Children to render */
|
|
473
|
+
children: React.ReactNode;
|
|
474
|
+
/** Optional pre-created auth provider */
|
|
475
|
+
authProvider?: DoAuthProvider;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* DoAuthProviderProvider
|
|
479
|
+
*
|
|
480
|
+
* A provider component that automatically creates and provides a DO-backed
|
|
481
|
+
* AuthProvider using the current DOProvider context.
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```tsx
|
|
485
|
+
* <DOProvider config={doConfig}>
|
|
486
|
+
* <DoAuthProviderProvider>
|
|
487
|
+
* <MyApp />
|
|
488
|
+
* </DoAuthProviderProvider>
|
|
489
|
+
* </DOProvider>
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
declare function DoAuthProviderProvider({ children, authProvider: providedAuthProvider, }: DoAuthProviderProviderProps): react_jsx_runtime.JSX.Element;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Merge class names with Tailwind CSS support
|
|
496
|
+
*/
|
|
497
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
498
|
+
/**
|
|
499
|
+
* Format a semantic ID (ns/type/id)
|
|
500
|
+
*/
|
|
501
|
+
declare function formatSemanticId(ns: string, type: string, id: string): string;
|
|
502
|
+
/**
|
|
503
|
+
* Parse a semantic ID into components
|
|
504
|
+
* Format: type/namespace/id where namespace can contain slashes
|
|
505
|
+
* @throws Error if the semantic ID format is invalid
|
|
506
|
+
*/
|
|
507
|
+
declare function parseSemanticId(semanticId: string): {
|
|
508
|
+
type: string;
|
|
509
|
+
namespace: string;
|
|
510
|
+
id: string;
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Format a date for display
|
|
514
|
+
*/
|
|
515
|
+
declare function formatDate(date: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
516
|
+
/**
|
|
517
|
+
* Format a date and time for display
|
|
518
|
+
*/
|
|
519
|
+
declare function formatDateTime(date: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
520
|
+
/**
|
|
521
|
+
* Format a relative time (e.g., "2 hours ago")
|
|
522
|
+
*/
|
|
523
|
+
declare function formatRelativeTime(date: Date | string): string;
|
|
524
|
+
/**
|
|
525
|
+
* Format a number with abbreviation (1K, 1M, etc.)
|
|
526
|
+
*/
|
|
527
|
+
declare function formatNumber(num: number): string;
|
|
528
|
+
/**
|
|
529
|
+
* Format bytes to human-readable string
|
|
530
|
+
*/
|
|
531
|
+
declare function formatBytes(bytes: number): string;
|
|
532
|
+
/**
|
|
533
|
+
* Format duration in milliseconds to human-readable string
|
|
534
|
+
*/
|
|
535
|
+
declare function formatDuration(ms: number): string;
|
|
536
|
+
/**
|
|
537
|
+
* Truncate text with ellipsis
|
|
538
|
+
*/
|
|
539
|
+
declare function truncate(text: string, maxLength: number, suffix?: string): string;
|
|
540
|
+
/**
|
|
541
|
+
* Capitalize first letter
|
|
542
|
+
*/
|
|
543
|
+
declare function capitalize(text: string): string;
|
|
544
|
+
/**
|
|
545
|
+
* Convert camelCase to Title Case
|
|
546
|
+
*/
|
|
547
|
+
declare function camelToTitle(text: string): string;
|
|
548
|
+
/**
|
|
549
|
+
* Generate a random ID
|
|
550
|
+
*/
|
|
551
|
+
declare function generateId(prefix?: string): string;
|
|
552
|
+
/**
|
|
553
|
+
* Debounce function
|
|
554
|
+
*
|
|
555
|
+
* Creates a debounced version of the function that delays execution
|
|
556
|
+
* until after the specified delay has passed since the last call.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```ts
|
|
560
|
+
* const debouncedSearch = debounce((query: string) => {
|
|
561
|
+
* fetch(`/search?q=${query}`)
|
|
562
|
+
* }, 300)
|
|
563
|
+
*
|
|
564
|
+
* // Only the last call within 300ms will execute
|
|
565
|
+
* debouncedSearch('h')
|
|
566
|
+
* debouncedSearch('he')
|
|
567
|
+
* debouncedSearch('hello') // Only this one runs
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
declare function debounce<Args extends unknown[]>(fn: (...args: Args) => unknown, delay: number): (...args: Args) => void;
|
|
571
|
+
/**
|
|
572
|
+
* Group array by key
|
|
573
|
+
*/
|
|
574
|
+
declare function groupBy<T, K extends string | number>(array: T[], keyFn: (item: T) => K): Record<K, T[]>;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Extended RequestInit that includes optional timeout
|
|
578
|
+
*/
|
|
579
|
+
interface FetchWithTimeoutOptions extends RequestInit {
|
|
580
|
+
/** Timeout in milliseconds. Defaults to 30000 (30 seconds) */
|
|
581
|
+
timeout?: number;
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Fetch wrapper with configurable timeout
|
|
585
|
+
*
|
|
586
|
+
* Uses AbortController to cancel requests that exceed the timeout.
|
|
587
|
+
* If the request already has a signal, a composite abort will be used
|
|
588
|
+
* that respects both the existing signal and the timeout.
|
|
589
|
+
*
|
|
590
|
+
* @param url - The URL to fetch
|
|
591
|
+
* @param options - Fetch options including optional timeout
|
|
592
|
+
* @returns Promise resolving to the Response
|
|
593
|
+
* @throws {DOMException} AbortError if the request times out
|
|
594
|
+
*
|
|
595
|
+
* @example
|
|
596
|
+
* ```typescript
|
|
597
|
+
* // Basic usage with default 30s timeout
|
|
598
|
+
* const response = await fetchWithTimeout('https://api.example.com/data')
|
|
599
|
+
*
|
|
600
|
+
* // Custom timeout
|
|
601
|
+
* const response = await fetchWithTimeout('https://api.example.com/data', {
|
|
602
|
+
* timeout: 5000, // 5 seconds
|
|
603
|
+
* })
|
|
604
|
+
*
|
|
605
|
+
* // With other fetch options
|
|
606
|
+
* const response = await fetchWithTimeout('https://api.example.com/data', {
|
|
607
|
+
* method: 'POST',
|
|
608
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
609
|
+
* body: JSON.stringify({ key: 'value' }),
|
|
610
|
+
* timeout: 10000,
|
|
611
|
+
* })
|
|
612
|
+
* ```
|
|
613
|
+
*/
|
|
614
|
+
declare function fetchWithTimeout(url: string, options?: FetchWithTimeoutOptions): Promise<Response>;
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Standardized error classes for @mdxui/do
|
|
618
|
+
*
|
|
619
|
+
* These classes provide consistent error handling across the package:
|
|
620
|
+
* - APIError: HTTP/RPC errors from the backend
|
|
621
|
+
* - NetworkError: Connection/fetch failures
|
|
622
|
+
* - ValidationError: Input validation errors
|
|
623
|
+
* - SyncError: Real-time sync errors
|
|
624
|
+
*
|
|
625
|
+
* @example
|
|
626
|
+
* ```typescript
|
|
627
|
+
* import { APIError, NetworkError, isAPIError } from '@mdxui/do'
|
|
628
|
+
*
|
|
629
|
+
* try {
|
|
630
|
+
* const response = await fetch(url)
|
|
631
|
+
* if (!response.ok) {
|
|
632
|
+
* throw APIError.fromResponse(response)
|
|
633
|
+
* }
|
|
634
|
+
* } catch (error) {
|
|
635
|
+
* if (isAPIError(error)) {
|
|
636
|
+
* console.log(`API error ${error.code}: ${error.message}`)
|
|
637
|
+
* if (error.status === 401) {
|
|
638
|
+
* // Handle auth error
|
|
639
|
+
* }
|
|
640
|
+
* } else if (isNetworkError(error)) {
|
|
641
|
+
* console.log('Network unavailable, will retry...')
|
|
642
|
+
* }
|
|
643
|
+
* }
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
/**
|
|
647
|
+
* API error from HTTP/RPC calls
|
|
648
|
+
*
|
|
649
|
+
* Provides structured error information including:
|
|
650
|
+
* - code: Machine-readable error code (e.g., 'HTTP_404', 'VALIDATION_ERROR')
|
|
651
|
+
* - message: Human-readable error message
|
|
652
|
+
* - status: HTTP status code (when applicable)
|
|
653
|
+
* - details: Additional error details from the server
|
|
654
|
+
*/
|
|
655
|
+
declare class APIError extends Error {
|
|
656
|
+
readonly code: string;
|
|
657
|
+
readonly status?: number | undefined;
|
|
658
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
659
|
+
constructor(code: string, message: string, status?: number | undefined, details?: Record<string, unknown> | undefined);
|
|
660
|
+
/**
|
|
661
|
+
* Create an APIError from a fetch Response
|
|
662
|
+
*
|
|
663
|
+
* @param response - The Response object from fetch
|
|
664
|
+
* @param body - Optional response body text (if already read)
|
|
665
|
+
* @returns An APIError with HTTP status information
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
* ```typescript
|
|
669
|
+
* const response = await fetch('/api/things')
|
|
670
|
+
* if (!response.ok) {
|
|
671
|
+
* throw APIError.fromResponse(response, await response.text())
|
|
672
|
+
* }
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
static fromResponse(response: Response, body?: string): APIError;
|
|
676
|
+
/**
|
|
677
|
+
* Type guard to check if an error is an APIError
|
|
678
|
+
*/
|
|
679
|
+
static isAPIError(error: unknown): error is APIError;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Network-level error (connection failures, timeouts, etc.)
|
|
683
|
+
*
|
|
684
|
+
* Use for errors that occur before an HTTP response is received:
|
|
685
|
+
* - DNS resolution failures
|
|
686
|
+
* - Connection refused
|
|
687
|
+
* - Request timeouts
|
|
688
|
+
* - CORS errors
|
|
689
|
+
*/
|
|
690
|
+
declare class NetworkError extends Error {
|
|
691
|
+
readonly cause?: Error | undefined;
|
|
692
|
+
constructor(message: string, cause?: Error | undefined);
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Validation error with field-level details
|
|
696
|
+
*
|
|
697
|
+
* Use when input data fails validation checks.
|
|
698
|
+
* The fields property maps field names to arrays of error messages.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* throw new ValidationError('Invalid input', {
|
|
703
|
+
* email: ['Invalid email format'],
|
|
704
|
+
* name: ['Name is required', 'Name must be at least 2 characters'],
|
|
705
|
+
* })
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
declare class ValidationError extends Error {
|
|
709
|
+
readonly fields: Record<string, string[]>;
|
|
710
|
+
constructor(message: string, fields: Record<string, string[]>);
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Real-time sync error
|
|
714
|
+
*
|
|
715
|
+
* Use for errors in the sync protocol (WebSocket, EventSource, etc.).
|
|
716
|
+
* The operation property indicates what sync operation failed.
|
|
717
|
+
* The recoverable property indicates whether the client should retry.
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```typescript
|
|
721
|
+
* // Recoverable connection error - client should retry
|
|
722
|
+
* throw new SyncError('WebSocket disconnected', 'connect', true)
|
|
723
|
+
*
|
|
724
|
+
* // Non-recoverable push error - user intervention needed
|
|
725
|
+
* throw new SyncError('Conflict: record modified by another user', 'push', false)
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
declare class SyncError extends Error {
|
|
729
|
+
readonly operation: 'push' | 'pull' | 'connect';
|
|
730
|
+
readonly recoverable: boolean;
|
|
731
|
+
constructor(message: string, operation: 'push' | 'pull' | 'connect', recoverable: boolean);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Type guard to check if an error is an APIError
|
|
735
|
+
*/
|
|
736
|
+
declare function isAPIError(error: unknown): error is APIError;
|
|
737
|
+
/**
|
|
738
|
+
* Type guard to check if an error is a NetworkError
|
|
739
|
+
*/
|
|
740
|
+
declare function isNetworkError(error: unknown): error is NetworkError;
|
|
741
|
+
/**
|
|
742
|
+
* Type guard to check if an error is a ValidationError
|
|
743
|
+
*/
|
|
744
|
+
declare function isValidationError(error: unknown): error is ValidationError;
|
|
745
|
+
/**
|
|
746
|
+
* Type guard to check if an error is a SyncError
|
|
747
|
+
*/
|
|
748
|
+
declare function isSyncError(error: unknown): error is SyncError;
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Typed RPC client for @mdxui/do
|
|
752
|
+
*
|
|
753
|
+
* Provides a unified interface for making RPC calls to the .do backend,
|
|
754
|
+
* with consistent error handling, timeouts, and authentication.
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```typescript
|
|
758
|
+
* // Create a client
|
|
759
|
+
* const client = createRPCClient({
|
|
760
|
+
* rpcUrl: 'https://api.do/rpc',
|
|
761
|
+
* authToken: 'xxx',
|
|
762
|
+
* timeout: 5000,
|
|
763
|
+
* })
|
|
764
|
+
*
|
|
765
|
+
* // Make typed RPC calls
|
|
766
|
+
* const things = await client.call<ListInput, Thing[]>('things.list', { limit: 10 })
|
|
767
|
+
* ```
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* ```typescript
|
|
771
|
+
* // Use the hook in a component
|
|
772
|
+
* function MyComponent() {
|
|
773
|
+
* const client = useRPCClient()
|
|
774
|
+
*
|
|
775
|
+
* if (!client) {
|
|
776
|
+
* return <div>RPC not available (REST mode)</div>
|
|
777
|
+
* }
|
|
778
|
+
*
|
|
779
|
+
* // Use client...
|
|
780
|
+
* }
|
|
781
|
+
* ```
|
|
782
|
+
*
|
|
783
|
+
* @module
|
|
784
|
+
*/
|
|
785
|
+
/**
|
|
786
|
+
* Configuration for creating an RPC client
|
|
787
|
+
*/
|
|
788
|
+
interface RPCClientConfig {
|
|
789
|
+
/** Base RPC URL (e.g., 'https://api.do/rpc') */
|
|
790
|
+
rpcUrl: string;
|
|
791
|
+
/** Optional auth token for Bearer authentication */
|
|
792
|
+
authToken?: string;
|
|
793
|
+
/** Request timeout in milliseconds (defaults to 30000) */
|
|
794
|
+
timeout?: number;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Options for an individual RPC call
|
|
798
|
+
*/
|
|
799
|
+
interface RPCCallOptions {
|
|
800
|
+
/** AbortSignal for cancelling the request mid-flight */
|
|
801
|
+
signal?: AbortSignal;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Typed RPC client interface
|
|
805
|
+
*/
|
|
806
|
+
interface RPCClient {
|
|
807
|
+
/**
|
|
808
|
+
* Make a typed RPC call
|
|
809
|
+
*
|
|
810
|
+
* @param method - The RPC method name (e.g., 'things.list', 'things.get')
|
|
811
|
+
* @param input - The input payload for the RPC method
|
|
812
|
+
* @param options - Optional call options including AbortSignal
|
|
813
|
+
* @returns Promise resolving to the typed output
|
|
814
|
+
* @throws {APIError} If the server returns a non-OK response
|
|
815
|
+
* @throws {NetworkError} If the network request fails
|
|
816
|
+
* @throws {DOMException} AbortError if the request is cancelled via signal
|
|
817
|
+
*/
|
|
818
|
+
call<TInput, TOutput>(method: string, input: TInput, options?: RPCCallOptions): Promise<TOutput>;
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Create a typed RPC client
|
|
822
|
+
*
|
|
823
|
+
* @param config - Client configuration
|
|
824
|
+
* @returns An RPC client instance
|
|
825
|
+
*
|
|
826
|
+
* @example
|
|
827
|
+
* ```typescript
|
|
828
|
+
* const client = createRPCClient({
|
|
829
|
+
* rpcUrl: 'https://api.do/rpc',
|
|
830
|
+
* authToken: 'jwt-token',
|
|
831
|
+
* timeout: 10000,
|
|
832
|
+
* })
|
|
833
|
+
*
|
|
834
|
+
* // List things
|
|
835
|
+
* const things = await client.call<{ limit: number }, Thing[]>('things.list', { limit: 10 })
|
|
836
|
+
*
|
|
837
|
+
* // Get a single thing
|
|
838
|
+
* const thing = await client.call<{ id: string }, Thing>('things.get', { id: 'thing-123' })
|
|
839
|
+
*
|
|
840
|
+
* // Create a thing
|
|
841
|
+
* const newThing = await client.call<CreateInput, Thing>('things.create', { name: 'New Thing' })
|
|
842
|
+
*
|
|
843
|
+
* // With AbortSignal for cancellation
|
|
844
|
+
* const controller = new AbortController()
|
|
845
|
+
* const things = await client.call<{ limit: number }, Thing[]>(
|
|
846
|
+
* 'things.list',
|
|
847
|
+
* { limit: 10 },
|
|
848
|
+
* { signal: controller.signal }
|
|
849
|
+
* )
|
|
850
|
+
* // To cancel: controller.abort()
|
|
851
|
+
* ```
|
|
852
|
+
*/
|
|
853
|
+
declare function createRPCClient(config: RPCClientConfig): RPCClient;
|
|
854
|
+
/**
|
|
855
|
+
* Hook to access an RPC client from the DO context
|
|
856
|
+
*
|
|
857
|
+
* Returns null when not in TanStack DB mode (i.e., when doUrl is not configured).
|
|
858
|
+
* The client is memoized and only recreated when the rpcUrl, authToken, or
|
|
859
|
+
* requestTimeout changes.
|
|
860
|
+
*
|
|
861
|
+
* @returns An RPC client instance, or null if RPC is not available
|
|
862
|
+
*
|
|
863
|
+
* @example
|
|
864
|
+
* ```typescript
|
|
865
|
+
* function ThingsList() {
|
|
866
|
+
* const client = useRPCClient()
|
|
867
|
+
* const [things, setThings] = useState<Thing[]>([])
|
|
868
|
+
*
|
|
869
|
+
* useEffect(() => {
|
|
870
|
+
* if (!client) return
|
|
871
|
+
*
|
|
872
|
+
* client.call<{ limit: number }, Thing[]>('things.list', { limit: 10 })
|
|
873
|
+
* .then(setThings)
|
|
874
|
+
* .catch(console.error)
|
|
875
|
+
* }, [client])
|
|
876
|
+
*
|
|
877
|
+
* if (!client) {
|
|
878
|
+
* return <div>RPC not available</div>
|
|
879
|
+
* }
|
|
880
|
+
*
|
|
881
|
+
* return <ul>{things.map(t => <li key={t.id}>{t.name}</li>)}</ul>
|
|
882
|
+
* }
|
|
883
|
+
* ```
|
|
884
|
+
*/
|
|
885
|
+
declare function useRPCClient(): RPCClient | null;
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Batch sync utilities for optimizing sync operations
|
|
889
|
+
*
|
|
890
|
+
* Batches rapid changes to reduce sync overhead and improve performance.
|
|
891
|
+
* Instead of syncing every mutation individually, changes are buffered
|
|
892
|
+
* and sent in batches.
|
|
893
|
+
*
|
|
894
|
+
* @module
|
|
895
|
+
*/
|
|
896
|
+
/**
|
|
897
|
+
* Options for batch sync operations
|
|
898
|
+
*/
|
|
899
|
+
interface BatchSyncOptions {
|
|
900
|
+
/** Maximum number of items before forcing a flush (default: 100) */
|
|
901
|
+
maxBatchSize?: number;
|
|
902
|
+
/** Maximum time to wait before flushing in ms (default: 50) */
|
|
903
|
+
maxWaitMs?: number;
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Return type for batched operations controller
|
|
907
|
+
*/
|
|
908
|
+
interface BatchedOperations<T> {
|
|
909
|
+
/** Add an item to the batch queue */
|
|
910
|
+
add: (item: T) => void;
|
|
911
|
+
/** Force flush all pending items immediately */
|
|
912
|
+
flush: () => Promise<void>;
|
|
913
|
+
/** Get the current number of pending items */
|
|
914
|
+
readonly pending: number;
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Create a batched operations controller
|
|
918
|
+
*
|
|
919
|
+
* Buffers items and executes them in batches to reduce overhead.
|
|
920
|
+
* Items are flushed when either:
|
|
921
|
+
* - The batch reaches maxBatchSize
|
|
922
|
+
* - maxWaitMs has elapsed since the first item was added
|
|
923
|
+
*
|
|
924
|
+
* @param executor - Function to execute with batched items
|
|
925
|
+
* @param options - Batch configuration options
|
|
926
|
+
* @returns Controller for managing batched operations
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```typescript
|
|
930
|
+
* const batchedSync = createBatchedOperations<Mutation>(
|
|
931
|
+
* async (mutations) => {
|
|
932
|
+
* await syncToServer(mutations)
|
|
933
|
+
* },
|
|
934
|
+
* { maxBatchSize: 50, maxWaitMs: 100 }
|
|
935
|
+
* )
|
|
936
|
+
*
|
|
937
|
+
* // These will be batched together
|
|
938
|
+
* batchedSync.add({ type: 'create', data: { name: 'A' } })
|
|
939
|
+
* batchedSync.add({ type: 'create', data: { name: 'B' } })
|
|
940
|
+
* batchedSync.add({ type: 'create', data: { name: 'C' } })
|
|
941
|
+
*
|
|
942
|
+
* // Force immediate flush if needed
|
|
943
|
+
* await batchedSync.flush()
|
|
944
|
+
* ```
|
|
945
|
+
*/
|
|
946
|
+
declare function createBatchedOperations<T>(executor: (items: T[]) => Promise<void>, options?: BatchSyncOptions): BatchedOperations<T>;
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Offline queue for mutation persistence during disconnection
|
|
950
|
+
*
|
|
951
|
+
* Queues mutations when offline and persists them to localStorage
|
|
952
|
+
* for replay when connection is restored.
|
|
953
|
+
*
|
|
954
|
+
* @module
|
|
955
|
+
*/
|
|
956
|
+
/**
|
|
957
|
+
* Options for offline queue
|
|
958
|
+
*/
|
|
959
|
+
interface OfflineQueueOptions {
|
|
960
|
+
/** Maximum number of items to queue (default: 1000) */
|
|
961
|
+
maxQueueSize?: number;
|
|
962
|
+
/** LocalStorage key for persistence (optional) */
|
|
963
|
+
persistKey?: string;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Offline queue controller interface
|
|
967
|
+
*/
|
|
968
|
+
interface OfflineQueue<T> {
|
|
969
|
+
/** Add an item to the queue. Returns false if queue is full. */
|
|
970
|
+
enqueue: (item: T) => boolean;
|
|
971
|
+
/** Remove and return all queued items */
|
|
972
|
+
dequeueAll: () => T[];
|
|
973
|
+
/** Peek at all items without removing */
|
|
974
|
+
peek: () => readonly T[];
|
|
975
|
+
/** Clear all items from the queue */
|
|
976
|
+
clear: () => void;
|
|
977
|
+
/** Current number of items in queue */
|
|
978
|
+
readonly length: number;
|
|
979
|
+
/** Whether queue is at capacity */
|
|
980
|
+
readonly isFull: boolean;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Create an offline queue for mutation persistence
|
|
984
|
+
*
|
|
985
|
+
* Queues items during offline periods and can persist to localStorage
|
|
986
|
+
* for durability across page refreshes.
|
|
987
|
+
*
|
|
988
|
+
* @param options - Queue configuration options
|
|
989
|
+
* @returns Offline queue controller
|
|
990
|
+
*
|
|
991
|
+
* @example
|
|
992
|
+
* ```typescript
|
|
993
|
+
* const queue = createOfflineQueue<Mutation>({
|
|
994
|
+
* maxQueueSize: 500,
|
|
995
|
+
* persistKey: 'my-app-offline-mutations'
|
|
996
|
+
* })
|
|
997
|
+
*
|
|
998
|
+
* // Queue mutations when offline
|
|
999
|
+
* if (!navigator.onLine) {
|
|
1000
|
+
* queue.enqueue({ type: 'create', data: { name: 'Test' } })
|
|
1001
|
+
* }
|
|
1002
|
+
*
|
|
1003
|
+
* // Replay when back online
|
|
1004
|
+
* window.addEventListener('online', async () => {
|
|
1005
|
+
* const mutations = queue.dequeueAll()
|
|
1006
|
+
* await syncMutations(mutations)
|
|
1007
|
+
* })
|
|
1008
|
+
* ```
|
|
1009
|
+
*/
|
|
1010
|
+
declare function createOfflineQueue<T>(options?: OfflineQueueOptions): OfflineQueue<T>;
|
|
1011
|
+
|
|
1012
|
+
export { APIError, type BatchSyncOptions, type BatchedOperations, DEFAULT_RESOURCE_TYPES, DOAdminConfig, DoAdmin, type DoAdminConfig, type DoAdminProps, type DoAuthProvider, DoAuthProviderProvider, type DoAuthProviderProviderProps, type DoDataProvider, DoDataProviderProvider, type DoDataProviderProviderProps, type DoFieldDefinition, type DoFieldType, type DoFilterDefinition, type DoLoginParams, type DoRecord, type DoResourceDefinition, type DoUserIdentity, type DoValidationRule, type FetchWithTimeoutOptions, NetworkError, type OfflineQueue, type OfflineQueueOptions, type RPCCallOptions, type RPCClient, type RPCClientConfig, SyncError, ThingSort, type UseDoAdminResult, ValidationError, camelToTitle, capitalize, cn, createBatchedOperations, createDoAuthProvider, createDoDataProvider, createOfflineQueue, createRPCClient, debounce, discoverResources, fetchWithTimeout, formatBytes, formatDate, formatDateTime, formatDuration, formatNumber, formatRelativeTime, formatSemanticId, generateId, groupBy, isAPIError, isNetworkError, isSyncError, isValidationError, mergeResourceOverrides, parseSemanticId, truncate, useDoAdmin, useRPCClient };
|