@mdxui/do 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +80 -275
  2. package/dist/app/index.d.ts +125 -125
  3. package/dist/app/index.js +8 -7
  4. package/dist/breadcrumbs-C9Qn3S7d.d.ts +81 -0
  5. package/dist/capnweb-client-Bq78FtEA.d.ts +229 -0
  6. package/dist/chunk-3XKYQRXY.js +192 -0
  7. package/dist/chunk-3XKYQRXY.js.map +1 -0
  8. package/dist/{chunk-JWKIONEO.js → chunk-5SHZZC7L.js} +3 -3
  9. package/dist/{chunk-JWKIONEO.js.map → chunk-5SHZZC7L.js.map} +1 -1
  10. package/dist/{chunk-YGIBMNRH.js → chunk-7UFINK3Q.js} +30 -27
  11. package/dist/chunk-7UFINK3Q.js.map +1 -0
  12. package/dist/{chunk-5AWTQDRF.js → chunk-JJLAES6W.js} +2 -2
  13. package/dist/{chunk-5AWTQDRF.js.map → chunk-JJLAES6W.js.map} +1 -1
  14. package/dist/{chunk-NTSEARBC.js → chunk-KT52UU3U.js} +473 -203
  15. package/dist/chunk-KT52UU3U.js.map +1 -0
  16. package/dist/{chunk-EQVOEEQO.js → chunk-LJIWB7KE.js} +2 -2
  17. package/dist/{chunk-EQVOEEQO.js.map → chunk-LJIWB7KE.js.map} +1 -1
  18. package/dist/{chunk-IESVTECE.js → chunk-NA652ART.js} +64 -4
  19. package/dist/chunk-NA652ART.js.map +1 -0
  20. package/dist/chunk-OVLO7UOH.js +1071 -0
  21. package/dist/chunk-OVLO7UOH.js.map +1 -0
  22. package/dist/chunk-WMNT4OIE.js +249 -0
  23. package/dist/chunk-WMNT4OIE.js.map +1 -0
  24. package/dist/components/index.d.ts +20 -1
  25. package/dist/components/index.js +2 -1
  26. package/dist/{config-CmZBQQaT.d.ts → config-CxvpD8Y6.d.ts} +2 -13
  27. package/dist/{do-C-t9UgjT.d.ts → do-D27i5bU0.d.ts} +2 -1
  28. package/dist/{errors-B4Oyyj4Z.d.ts → errors-DratdVIz.d.ts} +1 -1
  29. package/dist/hooks/index.d.ts +30 -3
  30. package/dist/hooks/index.js +4 -4
  31. package/dist/hooks/things/index.d.ts +2 -2
  32. package/dist/hooks/things/index.js +3 -3
  33. package/dist/index.d.ts +76 -14
  34. package/dist/index.js +9 -8
  35. package/dist/lib/index.d.ts +703 -5
  36. package/dist/lib/index.js +2 -2
  37. package/dist/providers/index.d.ts +7 -123
  38. package/dist/providers/index.js +2 -2
  39. package/dist/{query-keys-BC901wog.d.ts → query-keys-CZNFikIi.d.ts} +3 -3
  40. package/dist/schemas/index.d.ts +5 -5
  41. package/dist/{thing-BVhCTzOi.d.ts → thing-BF25aUtJ.d.ts} +68 -68
  42. package/dist/types/index.d.ts +445 -445
  43. package/dist/views/index.d.ts +1 -1
  44. package/dist/views/index.js +6 -6
  45. package/package.json +2 -2
  46. package/dist/chunk-FO3N7SXV.js +0 -469
  47. package/dist/chunk-FO3N7SXV.js.map +0 -1
  48. package/dist/chunk-IESVTECE.js.map +0 -1
  49. package/dist/chunk-NTSEARBC.js.map +0 -1
  50. package/dist/chunk-OWEAW4U6.js +0 -116
  51. package/dist/chunk-OWEAW4U6.js.map +0 -1
  52. package/dist/chunk-YGIBMNRH.js.map +0 -1
package/README.md CHANGED
@@ -3,33 +3,19 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@mdxui/do.svg)](https://www.npmjs.com/package/@mdxui/do)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- Admin interface for the .do platform - manage Durable Objects and Things with a full dashboard shell.
7
-
8
- ## What is @mdxui/do?
9
-
10
- `@mdxui/do` provides a React-based admin interface for the [.do platform](https://do.md). It includes a complete dashboard shell with routing, authentication (WorkOS AuthKit), and multiple view experiences: data browser, spreadsheet-style grid, document editor, and function executor. The library uses capnweb for RPC communication and `@mdxui/admin` for UI components.
6
+ React components and hooks for building admin interfaces for .do Durable Objects.
11
7
 
12
8
  ## Installation
13
9
 
14
10
  ```bash
15
- npm install @mdxui/do
16
- # or
17
11
  pnpm add @mdxui/do
18
- # or
19
- yarn add @mdxui/do
20
- ```
21
-
22
- ### Peer Dependencies
23
-
24
- ```bash
25
- npm install react react-dom
26
12
  ```
27
13
 
28
14
  ## Quick Start
29
15
 
30
- ### Complete Admin App
16
+ ### Full Admin Dashboard
31
17
 
32
- The easiest way to get started is with the `DOApp` component:
18
+ Use `DOApp` for a complete admin experience with routing and authentication:
33
19
 
34
20
  ```tsx
35
21
  import { DOApp } from '@mdxui/do/app'
@@ -45,43 +31,31 @@ function App() {
45
31
  realTimeUpdates: false,
46
32
  },
47
33
  identity: {
48
- clientId: 'client_xxx',
34
+ clientId: 'client_xxx', // WorkOS client ID
49
35
  devMode: true,
50
36
  },
51
- branding: {
52
- name: 'My Admin',
53
- },
54
- defaultNamespace: 'production',
55
37
  }}
56
38
  />
57
39
  )
58
40
  }
59
41
  ```
60
42
 
61
- This provides a complete admin experience with:
62
- - Dashboard shell with sidebar navigation
63
- - WorkOS AuthKit authentication
64
- - URL-based routing (Things, Databases, Functions, etc.)
65
- - Multiple view modes (browser, grid, document, function)
43
+ ### Custom UI with Provider
66
44
 
67
- ### Using the Provider Directly
68
-
69
- For custom UIs, wrap your app with `DOProvider`:
45
+ For custom UIs, use `DOProvider` directly:
70
46
 
71
47
  ```tsx
72
- import { DOProvider, useThings, useCreateThing } from '@mdxui/do'
48
+ import { DOProvider, useThings } from '@mdxui/do'
73
49
 
74
50
  function App() {
75
51
  return (
76
52
  <DOProvider
77
53
  config={{
78
54
  apiEndpoint: 'https://api.example.do',
79
- authMethod: 'jwt',
80
- authToken: 'your-token',
55
+ authMethod: 'none',
81
56
  bindings: [],
82
57
  realTimeUpdates: false,
83
58
  }}
84
- initialNamespace="default"
85
59
  >
86
60
  <TaskList />
87
61
  </DOProvider>
@@ -89,11 +63,9 @@ function App() {
89
63
  }
90
64
 
91
65
  function TaskList() {
92
- const { data, isLoading, error } = useThings({ type: 'Task' })
93
- const createThing = useCreateThing()
66
+ const { data, isLoading } = useThings({ type: 'Task' })
94
67
 
95
68
  if (isLoading) return <div>Loading...</div>
96
- if (error) return <div>Error: {error.message}</div>
97
69
 
98
70
  return (
99
71
  <ul>
@@ -105,293 +77,126 @@ function TaskList() {
105
77
  }
106
78
  ```
107
79
 
108
- ### Using the RPC Client Directly
109
-
110
- Access the capnweb client instance for direct RPC calls:
111
-
112
- ```tsx
113
- import { useDO, useDOClient } from '@mdxui/do'
114
-
115
- function MyComponent() {
116
- const { client, isConnected } = useDO()
117
- // or just: const client = useDOClient()
118
-
119
- const fetchData = async () => {
120
- // Promise pipelining - efficient batched RPC calls
121
- const [users, projects] = await Promise.all([
122
- client.Thing.list({ type: 'User' }),
123
- client.Thing.list({ type: 'Project' }),
124
- ])
125
- return { users, projects }
126
- }
127
- }
128
- ```
129
-
130
- ## Shell Components
80
+ ## Views
131
81
 
132
- ### DOApp
133
-
134
- Complete routed application with authentication and navigation:
82
+ Four view components for managing Things:
135
83
 
136
84
  ```tsx
137
- import { DOApp } from '@mdxui/do/app'
138
-
139
- <DOApp config={shellConfig} />
85
+ import {
86
+ DataBrowserView, // Browse/search with filtering
87
+ DataGridView, // Spreadsheet-style editing
88
+ DocumentEditorView, // Form-based editing
89
+ FunctionEditorView // Execute functions
90
+ } from '@mdxui/do/views'
140
91
  ```
141
92
 
142
- ### DOShell
93
+ ## Hooks
143
94
 
144
- Dashboard shell layout for custom routing setups:
95
+ ### Data Fetching
145
96
 
146
97
  ```tsx
147
- import { DOShell, DOShellNav } from '@mdxui/do/app'
148
-
149
- <DOShell>
150
- <YourContent />
151
- </DOShell>
152
- ```
98
+ import { useThings, useThing, useCreateThing } from '@mdxui/do'
153
99
 
154
- ### AuthGate
100
+ // List things
101
+ const { data } = useThings({ type: 'Task' })
155
102
 
156
- Authentication guard that shows sign-in when unauthenticated:
103
+ // Get single thing
104
+ const { data } = useThing({ ns: 'default', type: 'Task', id: 'task-1' })
157
105
 
158
- ```tsx
159
- import { AuthGate } from '@mdxui/do/app'
160
-
161
- <AuthGate>
162
- <ProtectedContent />
163
- </AuthGate>
106
+ // Create thing
107
+ const create = useCreateThing()
108
+ create.mutate({ ns: 'default', type: 'Task', name: 'New Task', data: {} })
164
109
  ```
165
110
 
166
- ## View Modes
167
-
168
- `@mdxui/do` provides four view experiences for managing Things:
169
-
170
- | View | Component | Description |
171
- |------|-----------|-------------|
172
- | **Data Browser** | `DataBrowserView` | Browse and search Things with filtering and sorting |
173
- | **Data Grid** | `DataGridView` | Spreadsheet-style editing with inline cell editing |
174
- | **Document Editor** | `DocumentEditorView` | Form-based editing for individual Things |
175
- | **Function Editor** | `FunctionEditorView` | Execute code/functions against the DO |
111
+ ### Discovery
176
112
 
177
113
  ```tsx
178
- import { DataBrowserView, DataGridView, DocumentEditorView } from '@mdxui/do/views'
114
+ import { useNamespaces, useTypes, useSchema } from '@mdxui/do'
179
115
 
180
- // Use individual views in your own layout
181
- function CustomAdmin() {
182
- return (
183
- <DOProvider config={config}>
184
- <DataBrowserView />
185
- </DOProvider>
186
- )
187
- }
116
+ const { data: namespaces } = useNamespaces()
117
+ const { data: types } = useTypes()
118
+ const { data: schema } = useSchema('Task')
188
119
  ```
189
120
 
190
- ## Core Concepts
191
-
192
- ### Things
121
+ ### State Management
193
122
 
194
- Things are semantic entities (nouns) that form the foundation of your data model:
195
-
196
- - **Namespace (`ns`)**: Tenant or domain isolation
197
- - **Type**: Entity classification (e.g., `"Task"`, `"User"`)
198
- - **ID**: Unique identifier within namespace/type
199
- - **Data**: JSON-LD compatible payload
123
+ Endpoint and namespace state is managed via TanStack Query with localStorage persistence:
200
124
 
201
125
  ```tsx
202
- import { useThings, useThing, useCreateThing } from '@mdxui/do'
203
-
204
- // Fetch multiple Things with filtering
205
- const { data } = useThings({ type: 'Task', nameSearch: 'urgent' })
206
-
207
- // Fetch a single Thing
208
- const { data: task } = useThing('default', 'Task', 'task-123')
126
+ import { useDOState, useEndpoint, useSetEndpoint } from '@mdxui/do'
209
127
 
210
- // Create a new Thing
211
- const createThing = useCreateThing()
212
- createThing.mutate({
213
- ns: 'default',
214
- type: 'Task',
215
- name: 'New Task',
216
- data: { priority: 'high' },
128
+ // Combined hook for all state
129
+ const { endpoint, setEndpoint, namespace, setNamespace, recentEndpoints } = useDOState({
130
+ endpoint: 'https://api.example.do', // Required: fallback from config
217
131
  })
218
- ```
219
-
220
- ### Schema Discovery
221
-
222
- Automatically discover available types and their schemas:
223
-
224
- ```tsx
225
- import { useSchema, useTypes, useNamespaces } from '@mdxui/do'
226
132
 
227
- // Get all namespaces
228
- const { data: namespaces } = useNamespaces()
229
-
230
- // Get all types in a namespace
231
- const { data: types } = useTypes({ namespace: 'default' })
232
-
233
- // Get schema for a specific type
234
- const { data: schema } = useSchema('Task')
133
+ // Or use individual hooks
134
+ const endpoint = useEndpoint('https://api.example.do')
135
+ const { mutate: setEndpoint } = useSetEndpoint()
235
136
  ```
236
137
 
237
- ### Real-time Subscriptions
138
+ State persists across sessions via localStorage and automatically invalidates data queries when the endpoint changes.
238
139
 
239
- Subscribe to Thing changes for real-time updates:
140
+ ## Architecture
240
141
 
241
- ```tsx
242
- import { useThingSubscription, useSingleThingSubscription } from '@mdxui/do'
243
-
244
- // Subscribe to all Things of a type
245
- useThingSubscription({
246
- type: 'Task',
247
- onEvent: (event) => {
248
- console.log('Thing changed:', event)
249
- },
250
- })
142
+ `DOApp` provides a complete admin dashboard with:
251
143
 
252
- // Subscribe to a single Thing
253
- useSingleThingSubscription({
254
- ns: 'default',
255
- type: 'Task',
256
- id: 'task-123',
257
- onEvent: (event) => {
258
- console.log('Task updated:', event)
259
- },
260
- })
261
- ```
144
+ - **TanStack Router** for client-side navigation
145
+ - **WorkOS AuthKit** for authentication
146
+ - **TanStack Query** for data fetching/caching
147
+ - **capnweb** for WebSocket RPC to Durable Objects
262
148
 
263
- ## Configuration
149
+ The auth flow:
150
+ 1. User signs in via WorkOS
151
+ 2. Access token is passed to `DOProvider`
152
+ 3. RPC calls include token as `?token=` query param
153
+ 4. Backend validates JWT
264
154
 
265
- ### DOShellConfig
155
+ ## Configuration
266
156
 
267
- Configuration for the complete `DOApp`:
157
+ ### DOAdminConfig (for DOProvider)
268
158
 
269
159
  | Property | Type | Required | Description |
270
160
  |----------|------|----------|-------------|
271
- | `do` | `DOAdminConfig` | Yes | RPC and API configuration |
272
- | `identity` | `DOIdentity` | Yes | WorkOS AuthKit configuration |
273
- | `basePath` | `string` | No | Base URL path for routing |
274
- | `defaultNamespace` | `string` | No | Initial namespace |
275
- | `branding` | `{ name?, logo? }` | No | Custom branding |
276
- | `theme` | `{ mode? }` | No | Theme preference (light/dark/system) |
277
- | `routes` | `Record<string, boolean>` | No | Enable/disable specific routes |
278
-
279
- ### DOAdminConfig
280
-
281
- | Property | Type | Required | Default | Description |
282
- |----------|------|----------|---------|-------------|
283
- | `apiEndpoint` | `string` | Yes | - | Base URL for API calls |
284
- | `rpcUrl` | `string` | No | `${apiEndpoint}/rpc` | Explicit RPC URL for capnweb session |
285
- | `authMethod` | `'none' \| 'jwt' \| 'api-key' \| 'oauth'` | Yes | - | Authentication method |
286
- | `authToken` | `string` | No | - | JWT token or API key |
287
- | `bindings` | `DOBinding[]` | Yes | - | Durable Object bindings |
288
- | `realTimeUpdates` | `boolean` | Yes | - | Enable real-time updates via RPC subscriptions |
289
- | `clientType` | `'capnweb' \| 'json-rpc'` | No | `'capnweb'` | RPC client type |
290
- | `requestTimeout` | `number` | No | `30000` | Request timeout in ms |
291
- | `skipHealthCheck` | `boolean` | No | `false` | Skip health check on connection |
292
- | `healthCheckRetries` | `number` | No | `3` | Number of health check retries |
293
-
294
- ### DOIdentity
161
+ | `apiEndpoint` | `string` | Yes | Base URL for API |
162
+ | `authMethod` | `'none' \| 'jwt' \| 'api-key'` | Yes | Auth method |
163
+ | `authToken` | `string` | No | JWT or API key |
164
+ | `bindings` | `DOBinding[]` | Yes | DO bindings |
165
+ | `realTimeUpdates` | `boolean` | Yes | Enable subscriptions |
166
+ | `clientType` | `'capnweb' \| 'json-rpc'` | No | RPC client type |
167
+
168
+ ### DOShellConfig (for DOApp)
295
169
 
296
170
  | Property | Type | Required | Description |
297
171
  |----------|------|----------|-------------|
298
- | `clientId` | `string` | Yes | WorkOS client ID |
299
- | `apiHostname` | `string` | No | WorkOS API hostname |
300
- | `devMode` | `boolean` | No | Enable development mode |
301
- | `redirectUri` | `string` | No | OAuth redirect URI |
172
+ | `do` | `DOAdminConfig` | Yes | API config |
173
+ | `identity` | `DOIdentity` | Yes | WorkOS auth config |
174
+ | `branding` | `{ name?, logo? }` | No | Branding |
175
+ | `basePath` | `string` | No | URL base path |
302
176
 
303
- ## Available Hooks
304
-
305
- ### Context Hooks
306
-
307
- | Hook | Description |
308
- |------|-------------|
309
- | `useDO()` | Access DO context (config, namespace, client, connection state) |
310
- | `useDOClient()` | Access the capnweb client instance directly |
311
- | `useDOUrls()` | Get derived URLs (rpcUrl, apiEndpoint) |
312
- | `useIdentity()` | Access WorkOS auth state (from AuthKit) |
313
- | `useDOShell()` | Access shell config and navigation state |
314
-
315
- ### Things Hooks
316
-
317
- | Hook | Description |
318
- |------|-------------|
319
- | `useThings(filter?)` | Fetch paginated Things with filtering |
320
- | `useThing(ns, type, id)` | Fetch a single Thing |
321
- | `useThingVersions(ns, type, id)` | Fetch version history for a Thing |
322
- | `useTypeStats(type)` | Fetch statistics for a Thing type |
323
- | `useCreateThing()` | Create a new Thing |
324
- | `useUpdateThing(ns, type, id)` | Update an existing Thing |
325
- | `useDeleteThing(ns, type, id)` | Delete a Thing |
326
-
327
- ### Discovery Hooks
328
-
329
- | Hook | Description |
330
- |------|-------------|
331
- | `useSchema(type)` | Get schema for a Thing type |
332
- | `useSchemaDefinition(type)` | Get detailed schema definition |
333
- | `useNamespaces()` | List available namespaces |
334
- | `useTypes(options?)` | List available Thing types |
335
-
336
- ### Subscription Hooks
337
-
338
- | Hook | Description |
339
- |------|-------------|
340
- | `useThingSubscription(options)` | Subscribe to Thing changes |
341
- | `useSingleThingSubscription(options)` | Subscribe to a single Thing |
342
-
343
- ## Subpath Exports
177
+ ## Exports
344
178
 
345
179
  ```tsx
346
- // Full package - types, providers, hooks, components, views, app
180
+ // Main
347
181
  import { DOProvider, useThings, DOApp } from '@mdxui/do'
348
182
 
349
- // App components - DOApp, DOShell, pages, routes
350
- import { DOApp, DOShell, DOShellNav, AuthGate } from '@mdxui/do/app'
183
+ // App (routing, shell, auth)
184
+ import { DOApp, DOShell, AuthGate } from '@mdxui/do/app'
351
185
 
352
- // Providers - DOProvider and context hooks
353
- import { DOProvider, useDO, useDOClient } from '@mdxui/do/providers'
186
+ // Providers
187
+ import { DOProvider, useDO } from '@mdxui/do/providers'
354
188
 
355
- // Hooks - all data fetching hooks
356
- import { useThings, useSchema, useNamespaces } from '@mdxui/do/hooks'
189
+ // Hooks
190
+ import { useThings, useCreateThing } from '@mdxui/do/hooks'
357
191
 
358
- // Things-specific hooks
359
- import { useThings, useCreateThing } from '@mdxui/do/hooks/things'
192
+ // State (TanStack Query-based)
193
+ import { useDOState, useEndpoint, useSetEndpoint, useNamespace } from '@mdxui/do'
360
194
 
361
- // Views - the 4 view experiences
195
+ // Views
362
196
  import { DataBrowserView, DataGridView } from '@mdxui/do/views'
363
197
 
364
- // Components - UI components
365
- import { ErrorBoundary } from '@mdxui/do/components'
366
-
367
- // Types - TypeScript types
368
- import type { Thing, DOAdminConfig, ThingFilter } from '@mdxui/do/types'
369
-
370
- // Schemas - Zod schemas for validation
371
- import { ThingSchema, ThingFilterSchema } from '@mdxui/do/schemas'
372
-
373
- // Lib - utilities
374
- import { cn, formatDate, APIError } from '@mdxui/do/lib'
375
- ```
376
-
377
- ## Architecture
378
-
379
- ```
380
- @mdxui/do
381
- ├── app/ # DOApp, DOShell, pages, routes, auth
382
- ├── providers/ # DOProvider, context hooks
383
- ├── hooks/ # Data fetching hooks (Things, Schema, etc.)
384
- ├── views/ # View components (Browser, Grid, Document, Function)
385
- ├── components/ # Shared UI components
386
- ├── types/ # TypeScript types + Zod schemas
387
- └── lib/ # Utilities (cn, errors, formatters)
388
-
389
- Dependencies:
390
- ├── capnweb # Binary RPC over HTTP
391
- ├── @workos-inc/authkit # Authentication
392
- ├── @mdxui/admin # UI components
393
- ├── @mdxui/primitives # Base UI primitives
394
- └── @tanstack/react-query # Data fetching & caching
198
+ // Types
199
+ import type { Thing, DOAdminConfig } from '@mdxui/do/types'
395
200
  ```
396
201
 
397
202
  ## License