yk-grid 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +355 -0
- package/dist/server.cjs +88 -0
- package/dist/server.mjs +3144 -0
- package/dist/types/DataGrid.d.ts +5 -0
- package/dist/types/ai/aiClient.d.ts +3 -0
- package/dist/types/ai/applyCommand.d.ts +3 -0
- package/dist/types/ai/schema.d.ts +28 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/server/gridAiRoute.d.ts +47 -0
- package/dist/types/server/index.d.ts +1 -0
- package/dist/types/server/providers/anthropic.d.ts +7 -0
- package/dist/types/server/providers/openai.d.ts +7 -0
- package/dist/types/server/providers/types.d.ts +3 -0
- package/dist/types/server/schema.d.ts +28 -0
- package/dist/types/state/aggregations.d.ts +2 -0
- package/dist/types/state/exportCsv.d.ts +3 -0
- package/dist/types/state/gridReducer.d.ts +43 -0
- package/dist/types/state/paginate.d.ts +3 -0
- package/dist/types/state/processRows.d.ts +5 -0
- package/dist/types/state/selection.d.ts +1 -0
- package/dist/types/state/useGridState.d.ts +8 -0
- package/dist/types/types.d.ts +106 -0
- package/dist/types/ui/AiBar.d.ts +13 -0
- package/dist/types/ui/Cell.d.ts +13 -0
- package/dist/types/ui/ColumnMenu.d.ts +10 -0
- package/dist/types/ui/FilterPanel.d.ts +11 -0
- package/dist/types/ui/GroupRow.d.ts +9 -0
- package/dist/types/ui/HeaderCell.d.ts +21 -0
- package/dist/types/ui/NumberFilter.d.ts +9 -0
- package/dist/types/ui/Pagination.d.ts +10 -0
- package/dist/types/ui/Row.d.ts +20 -0
- package/dist/types/ui/SelectionCell.d.ts +10 -0
- package/dist/types/ui/Toolbar.d.ts +21 -0
- package/dist/yk-grid.cjs.js +8 -0
- package/dist/yk-grid.css +2 -0
- package/dist/yk-grid.es.js +1973 -0
- package/package.json +90 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yemi Kehinde
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# yk-grid
|
|
2
|
+
|
|
3
|
+
A production-ready React DataGrid component with built-in sorting, filtering, grouping, pagination, selection, column management, CSV export, virtual scrolling, inline cell editing, and optional AI-assisted natural-language query input.
|
|
4
|
+
|
|
5
|
+
Dual-format library (ESM + CJS) with full TypeScript generics. Zero runtime dependencies beyond React, Zod, and @tanstack/react-virtual.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Sorting** — multi-column, asc/desc, shift-click to stack
|
|
12
|
+
- **Filtering** — funnel icon per column; text, number (with operator picker), select (searchable checkboxes), and date filter types
|
|
13
|
+
- **Grouping** — nest rows by one or more columns with collapse/expand
|
|
14
|
+
- **Aggregations** — sum, avg, count, min, max per group
|
|
15
|
+
- **Pagination** — client-side or server-side, with configurable page sizes
|
|
16
|
+
- **Virtual scrolling** — renders only visible rows for large datasets (pass `height`)
|
|
17
|
+
- **Row selection** — single or multiple, with page or filtered-set select-all scope
|
|
18
|
+
- **Inline cell editing** — double-click any `editable` cell; Enter/Tab commits, Escape cancels
|
|
19
|
+
- **Column resizing** — drag column edges to resize
|
|
20
|
+
- **Column visibility** — show/hide columns via per-column menu
|
|
21
|
+
- **CSV export** — export visible or selected rows
|
|
22
|
+
- **Custom toolbar actions** — inject buttons or controls into the toolbar via a render prop
|
|
23
|
+
- **AI query input** — optional natural-language command bar backed by your own endpoint
|
|
24
|
+
- **Imperative ref API** — programmatically read state, clear selection, trigger export
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install yk-grid
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Peer dependencies:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install react react-dom zod
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Import the library stylesheet once in your app entry point:
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import 'yk-grid/dist/yk-grid.css'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import 'yk-grid/dist/yk-grid.css'
|
|
52
|
+
import { DataGrid } from 'yk-grid'
|
|
53
|
+
import type { ColumnDef } from 'yk-grid'
|
|
54
|
+
|
|
55
|
+
interface User {
|
|
56
|
+
id: string
|
|
57
|
+
name: string
|
|
58
|
+
email: string
|
|
59
|
+
age: number
|
|
60
|
+
status: 'active' | 'inactive'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const columns: ColumnDef<User>[] = [
|
|
64
|
+
{ id: 'name', header: 'Name', accessor: r => r.name, sortable: true, filterable: true },
|
|
65
|
+
{ id: 'email', header: 'Email', accessor: r => r.email, sortable: true, filterable: true },
|
|
66
|
+
{ id: 'age', header: 'Age', accessor: r => r.age, sortable: true, filterType: 'number', editable: true },
|
|
67
|
+
{ id: 'status', header: 'Status', accessor: r => r.status, sortable: true, filterType: 'select' },
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
export default function App() {
|
|
71
|
+
return (
|
|
72
|
+
<DataGrid<User>
|
|
73
|
+
data={users}
|
|
74
|
+
columns={columns}
|
|
75
|
+
getRowId={r => r.id}
|
|
76
|
+
dataMode="client"
|
|
77
|
+
pageSize={50}
|
|
78
|
+
height={600}
|
|
79
|
+
selectionMode="multiple"
|
|
80
|
+
enableColumnResize
|
|
81
|
+
enableColumnVisibility
|
|
82
|
+
onCellEdit={(value, row, col) => console.log(col.id, row.id, '→', value)}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Column definition (`ColumnDef<T>`)
|
|
91
|
+
|
|
92
|
+
Every column is defined with a `ColumnDef<T>` object.
|
|
93
|
+
|
|
94
|
+
| Property | Type | Description |
|
|
95
|
+
|----------|------|-------------|
|
|
96
|
+
| `id` | `string` | Unique column identifier |
|
|
97
|
+
| `header` | `string` | Column header label |
|
|
98
|
+
| `accessor` | `(row: T) => string \| number \| Date \| null` | Extracts the raw cell value from the row |
|
|
99
|
+
| `cell` | `(value, row: T) => ReactNode` | Optional custom cell renderer |
|
|
100
|
+
| `exportValue` | `(row: T) => string \| number` | Override the value used in CSV export |
|
|
101
|
+
| `sortable` | `boolean` | Enable sort on this column |
|
|
102
|
+
| `filterable` | `boolean` | Show the funnel filter button for this column |
|
|
103
|
+
| `filterType` | `'text' \| 'number' \| 'select' \| 'date'` | Filter panel variant. Defaults to `'text'` |
|
|
104
|
+
| `filterOptions` | `string[]` | Static options for `filterType: 'select'` |
|
|
105
|
+
| `groupable` | `boolean` | Allow this column to be used as a grouping key |
|
|
106
|
+
| `aggregation` | `'sum' \| 'avg' \| 'count' \| 'min' \| 'max'` | Aggregation shown in group header rows |
|
|
107
|
+
| `editable` | `boolean` | Double-click to edit the cell inline |
|
|
108
|
+
| `width` | `number` | Default column width in pixels |
|
|
109
|
+
| `minWidth` | `number` | Minimum width when resizing (default: 50) |
|
|
110
|
+
| `resizable` | `boolean` | Override per-column resize (default: inherits `enableColumnResize`) |
|
|
111
|
+
| `hideable` | `boolean` | Whether this column can be hidden in the visibility picker |
|
|
112
|
+
| `defaultHidden` | `boolean` | Start the column hidden |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Props
|
|
117
|
+
|
|
118
|
+
### Required
|
|
119
|
+
|
|
120
|
+
| Prop | Type | Description |
|
|
121
|
+
|------|------|-------------|
|
|
122
|
+
| `data` | `T[]` | Row data |
|
|
123
|
+
| `columns` | `ColumnDef<T>[]` | Column definitions |
|
|
124
|
+
| `getRowId` | `(row: T) => string` | Unique row identifier function |
|
|
125
|
+
|
|
126
|
+
### Data & loading
|
|
127
|
+
|
|
128
|
+
| Prop | Type | Default | Description |
|
|
129
|
+
|------|------|---------|-------------|
|
|
130
|
+
| `dataMode` | `'client' \| 'server'` | `'server'` | `client` handles sort/filter/page locally; `server` fires `onStateChange` for you to fetch |
|
|
131
|
+
| `pageSize` | `number` | `20` | Initial rows per page |
|
|
132
|
+
| `rowCount` | `number` | — | Total row count for server-side pagination |
|
|
133
|
+
| `loading` | `boolean` | `false` | Shows a loading overlay |
|
|
134
|
+
| `onStateChange` | `(state: GridState) => void` | — | Fires when sorts, filters, grouping, or pagination change |
|
|
135
|
+
| `initialState` | `Partial<GridState>` | — | Seed initial sorts, filters, grouping, pagination, etc. |
|
|
136
|
+
|
|
137
|
+
### Selection
|
|
138
|
+
|
|
139
|
+
| Prop | Type | Default | Description |
|
|
140
|
+
|------|------|---------|-------------|
|
|
141
|
+
| `selectionMode` | `'none' \| 'single' \| 'multiple'` | `'none'` | Row selection behaviour |
|
|
142
|
+
| `selectAllScope` | `'page' \| 'filtered'` | `'page'` | What the select-all checkbox targets |
|
|
143
|
+
| `onSelectionChange` | `(rows: T[], ids: string[]) => void` | — | Fires whenever the selection changes |
|
|
144
|
+
|
|
145
|
+
### Click handlers
|
|
146
|
+
|
|
147
|
+
| Prop | Type | Description |
|
|
148
|
+
|------|------|-------------|
|
|
149
|
+
| `onRowClick` | `(row: T, index: number, e: MouseEvent) => void` | Called when a data row is clicked |
|
|
150
|
+
| `onCellClick` | `(value, row: T, column: ColumnDef<T>, e: MouseEvent) => void` | Called when an individual cell is clicked |
|
|
151
|
+
|
|
152
|
+
### Column features
|
|
153
|
+
|
|
154
|
+
| Prop | Type | Default | Description |
|
|
155
|
+
|------|------|---------|-------------|
|
|
156
|
+
| `enableColumnResize` | `boolean` | `false` | Drag-to-resize column widths |
|
|
157
|
+
| `enableColumnVisibility` | `boolean` | `false` | Show/hide column picker in header menus |
|
|
158
|
+
|
|
159
|
+
### Filtering
|
|
160
|
+
|
|
161
|
+
| Prop | Type | Description |
|
|
162
|
+
|------|------|-------------|
|
|
163
|
+
| `fetchFilterOptions` | `(columnId: string) => Promise<string[]>` | Server mode: fetch options for `filterType: 'select'` columns |
|
|
164
|
+
|
|
165
|
+
### Virtual scrolling
|
|
166
|
+
|
|
167
|
+
| Prop | Type | Default | Description |
|
|
168
|
+
|------|------|---------|-------------|
|
|
169
|
+
| `height` | `number \| string` | — | Fixed height activates virtual scrolling (e.g. `600` or `'80vh'`) |
|
|
170
|
+
| `estimatedRowHeight` | `number` | `41` | Row height hint for the virtualiser; affects scroll accuracy |
|
|
171
|
+
|
|
172
|
+
### Inline editing
|
|
173
|
+
|
|
174
|
+
| Prop | Type | Description |
|
|
175
|
+
|------|------|-------------|
|
|
176
|
+
| `onCellEdit` | `(newValue: string \| number, row: T, column: ColumnDef<T>) => void` | Called when a cell edit is committed. Set `editable: true` on columns you want editable. |
|
|
177
|
+
|
|
178
|
+
### Export
|
|
179
|
+
|
|
180
|
+
| Prop | Type | Default | Description |
|
|
181
|
+
|------|------|---------|-------------|
|
|
182
|
+
| `enableCsvExport` | `boolean` | `false` | Adds CSV export button to toolbar |
|
|
183
|
+
| `csvFilename` | `string` | `'export.csv'` | Downloaded file name |
|
|
184
|
+
|
|
185
|
+
### Toolbar
|
|
186
|
+
|
|
187
|
+
| Prop | Type | Description |
|
|
188
|
+
|------|------|-------------|
|
|
189
|
+
| `toolbarActions` | `(ctx: ToolbarCtx<T>) => ReactNode` | Render prop injected into the toolbar |
|
|
190
|
+
|
|
191
|
+
`ToolbarCtx<T>` contains: `selectedRows`, `selectedIds`, `processedRows`, `gridState`, `clearSelection`.
|
|
192
|
+
|
|
193
|
+
### AI
|
|
194
|
+
|
|
195
|
+
| Prop | Type | Description |
|
|
196
|
+
|------|------|-------------|
|
|
197
|
+
| `ai` | `{ endpoint: string; placeholder?: string }` | Enables the natural-language command bar |
|
|
198
|
+
|
|
199
|
+
### Display
|
|
200
|
+
|
|
201
|
+
| Prop | Type | Description |
|
|
202
|
+
|------|------|-------------|
|
|
203
|
+
| `emptyState` | `ReactNode` | Custom content when there are no rows |
|
|
204
|
+
| `className` | `string` | Class applied to the root wrapper element |
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## Imperative ref (`GridRef<T>`)
|
|
209
|
+
|
|
210
|
+
Pass a `ref` to read state and trigger actions programmatically:
|
|
211
|
+
|
|
212
|
+
```tsx
|
|
213
|
+
import { useRef } from 'react'
|
|
214
|
+
import { DataGrid, GridRef } from 'yk-grid'
|
|
215
|
+
|
|
216
|
+
const gridRef = useRef<GridRef<User>>(null)
|
|
217
|
+
|
|
218
|
+
<DataGrid ref={gridRef} ... />
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
| Method | Returns | Description |
|
|
222
|
+
|--------|---------|-------------|
|
|
223
|
+
| `getSelectedRows()` | `T[]` | Currently selected row objects |
|
|
224
|
+
| `getProcessedRows()` | `T[]` | All rows after filtering (ignores pagination) |
|
|
225
|
+
| `getGridState()` | `GridState` | Full current grid state snapshot |
|
|
226
|
+
| `clearSelection()` | `void` | Clear all selected rows |
|
|
227
|
+
| `exportCsv(opts?)` | `void` | Trigger CSV download. `opts.selectedOnly` exports selection only |
|
|
228
|
+
| `setState(partial)` | `void` | Programmatically set sorts, filters, or grouping |
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Theming
|
|
233
|
+
|
|
234
|
+
All visual properties are controlled via CSS custom properties on `:root` (or any ancestor element):
|
|
235
|
+
|
|
236
|
+
| Variable | Default | Description |
|
|
237
|
+
|----------|---------|-------------|
|
|
238
|
+
| `--grid-font-size` | `0.875rem` | Base font size |
|
|
239
|
+
| `--grid-border-colour` | `#e2e8f0` | Cell/row border colour |
|
|
240
|
+
| `--grid-header-bg` | `#f1f5f9` | Header and toolbar background |
|
|
241
|
+
| `--grid-row-hover-bg` | `#f8fafc` | Row hover background |
|
|
242
|
+
| `--grid-selected-bg` | `#eef2ff` | Selected row background |
|
|
243
|
+
| `--grid-accent` | `#6366f1` | Accent colour (focus rings, active filters, sort indicators) |
|
|
244
|
+
| `--grid-focus-ring` | `0 0 0 2px #6366f1` | Focus ring box-shadow |
|
|
245
|
+
| `--grid-radius` | `0.5rem` | Border radius of the outer wrapper |
|
|
246
|
+
| `--grid-cell-padding` | `0.625rem 0.875rem` | Cell padding (shorthand) |
|
|
247
|
+
| `--grid-cell-padding-y` | `0.625rem` | Vertical cell padding |
|
|
248
|
+
| `--grid-cell-padding-x` | `0.875rem` | Horizontal cell padding |
|
|
249
|
+
| `--grid-toolbar-gap` | `0.5rem` | Toolbar item gap |
|
|
250
|
+
|
|
251
|
+
Example — dark theme:
|
|
252
|
+
|
|
253
|
+
```css
|
|
254
|
+
.my-dark-wrapper {
|
|
255
|
+
--grid-border-colour: #334155;
|
|
256
|
+
--grid-header-bg: #1e293b;
|
|
257
|
+
--grid-row-hover-bg: #1e293b;
|
|
258
|
+
--grid-selected-bg: #312e81;
|
|
259
|
+
--grid-accent: #818cf8;
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Server mode
|
|
266
|
+
|
|
267
|
+
In `dataMode="server"`, the grid fires `onStateChange` whenever the user sorts, filters, groups, or paginates. Use this to fetch from your API:
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
const [data, setData] = useState<User[]>([])
|
|
271
|
+
const [rowCount, setRowCount] = useState(0)
|
|
272
|
+
const [loading, setLoading] = useState(false)
|
|
273
|
+
|
|
274
|
+
async function fetchData(state: GridState) {
|
|
275
|
+
setLoading(true)
|
|
276
|
+
const res = await fetch('/api/users', {
|
|
277
|
+
method: 'POST',
|
|
278
|
+
body: JSON.stringify(state),
|
|
279
|
+
})
|
|
280
|
+
const json = await res.json()
|
|
281
|
+
setData(json.rows)
|
|
282
|
+
setRowCount(json.total)
|
|
283
|
+
setLoading(false)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
<DataGrid<User>
|
|
287
|
+
dataMode="server"
|
|
288
|
+
data={data}
|
|
289
|
+
columns={columns}
|
|
290
|
+
getRowId={r => r.id}
|
|
291
|
+
rowCount={rowCount}
|
|
292
|
+
loading={loading}
|
|
293
|
+
onStateChange={fetchData}
|
|
294
|
+
/>
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## AI integration
|
|
300
|
+
|
|
301
|
+
The AI bar accepts natural-language queries and translates them into grid actions (sort, filter, group) via your endpoint.
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
<DataGrid
|
|
305
|
+
ai={{
|
|
306
|
+
endpoint: '/api/grid-ai',
|
|
307
|
+
placeholder: 'e.g. "show failed refunds over £200, sorted by amount"',
|
|
308
|
+
}}
|
|
309
|
+
...
|
|
310
|
+
/>
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Wire up the server handler (Express or Next.js App Router):
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
// Express
|
|
317
|
+
import { handleGridAiRequest } from 'yk-grid/server'
|
|
318
|
+
|
|
319
|
+
app.post('/api/grid-ai', async (req, res) => {
|
|
320
|
+
const result = await handleGridAiRequest(req.body)
|
|
321
|
+
res.json(result)
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
// Next.js App Router
|
|
325
|
+
import { handleGridAiRequest } from 'yk-grid/server'
|
|
326
|
+
|
|
327
|
+
export async function POST(req: Request) {
|
|
328
|
+
const body = await req.json()
|
|
329
|
+
const result = await handleGridAiRequest(body)
|
|
330
|
+
return Response.json(result)
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Set `ANTHROPIC_API_KEY` in your environment. To use OpenAI instead, set `LLM_PROVIDER=openai` and `OPENAI_API_KEY`.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Development
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
npm run dev:example # Vite dev server at localhost:5173 (example app + AI middleware)
|
|
342
|
+
npm test # vitest single pass
|
|
343
|
+
npm run test:watch # vitest watch
|
|
344
|
+
npm run typecheck # tsc --noEmit
|
|
345
|
+
npm run build # typecheck + vite build → dist/
|
|
346
|
+
npx playwright test # E2E smoke tests (requires: npx playwright install chromium)
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Set `ANTHROPIC_API_KEY` in `example/.env.local` to use the AI bar during development.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Licence
|
|
354
|
+
|
|
355
|
+
MIT
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=class{apiKey;model;constructor(e=process.env.ANTHROPIC_API_KEY??``,t=`claude-haiku-4-5-20251001`){if(!e)throw Error(`ANTHROPIC_API_KEY is not set`);this.apiKey=e,this.model=t}async complete(e,t){let n=await fetch(`https://api.anthropic.com/v1/messages`,{method:`POST`,headers:{"Content-Type":`application/json`,"x-api-key":this.apiKey,"anthropic-version":`2023-06-01`},body:JSON.stringify({model:this.model,max_tokens:1024,system:e,messages:[{role:`user`,content:t}]})});if(!n.ok){let e=await n.text();throw console.error(`Anthropic API error ${n.status}: ${e}`),Error(`AI request failed (status ${n.status})`)}let r=(await n.json()).content.find(e=>e.type===`text`);if(!r)throw Error(`No text block in Anthropic response`);return r.text}},t=class{apiKey;model;constructor(e=process.env.OPENAI_API_KEY??``,t=`gpt-4o-mini`){if(!e)throw Error(`OPENAI_API_KEY is not set`);this.apiKey=e,this.model=t}async complete(e,t){let n=await fetch(`https://api.openai.com/v1/chat/completions`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${this.apiKey}`},body:JSON.stringify({model:this.model,response_format:{type:`json_object`},messages:[{role:`system`,content:e},{role:`user`,content:t}]})});if(!n.ok){let e=await n.text();throw console.error(`OpenAI API error ${n.status}: ${e}`),Error(`AI request failed (status ${n.status})`)}return(await n.json()).choices[0].message.content}},n;function r(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}var i=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},a=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(n=globalThis).__zod_globalConfig??(n.__zod_globalConfig={});var o=globalThis.__zod_globalConfig;function s(e){return e&&Object.assign(o,e),o}function c(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function l(e,t){return typeof t==`bigint`?t.toString():t}function u(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}throw Error(`cached value already set`)}}}function d(e){return e==null}function f(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function p(e,t){let n=e/t,r=Math.round(n),i=2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}var ee=Symbol(`evaluating`);function m(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==ee)return r===void 0&&(r=ee,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function h(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function g(...e){let t={};for(let n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function te(e){return JSON.stringify(e)}function ne(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var re=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function _(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var ie=u(()=>{if(o.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function v(e){if(_(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return!(_(n)===!1||Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)===!1)}function ae(e){return v(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var oe=new Set([`string`,`number`,`symbol`]);function y(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function b(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function x(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function se(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}var ce={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function le(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return b(e,g(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return h(this,`shape`,e),e},checks:[]}))}function ue(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return b(e,g(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return h(this,`shape`,r),r},checks:[]}))}function de(e,t){if(!v(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return b(e,g(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return h(this,`shape`,n),n}}))}function fe(e,t){if(!v(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return b(e,g(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return h(this,`shape`,n),n}}))}function pe(e,t){if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);return b(e,g(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return h(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function me(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return b(t,g(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return h(this,`shape`,i),i},checks:[]}))}function he(e,t,n){return b(t,g(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return h(this,`shape`,i),i}}))}function S(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function ge(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function _e(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function C(e){return typeof e==`string`?e:e?.message}function w(e,t,n){let r=e.message?e.message:C(e.inst?._zod.def?.error?.(e))??C(t?.error?.(e))??C(n.customError?.(e))??C(n.localeError?.(e))??`Invalid input`,{inst:i,continue:a,input:o,...s}=e;return s.path??=[],s.message=r,t?.reportInput&&(s.input=o),s}function T(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function E(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var ve=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,l,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},ye=r(`$ZodError`,ve),be=r(`$ZodError`,ve,{Parent:Error});function xe(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Se(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i];i===e.length-1?(r[n]=r[n]||{_errors:[]},r[n]._errors.push(t(a))):r[n]=r[n]||{_errors:[]},r=r[n],i++}}}};return r(e),n}var D=e=>(t,n,r,a)=>{let o=r?{...r,async:!1}:{async:!1},c=t._zod.run({value:n,issues:[]},o);if(c instanceof Promise)throw new i;if(c.issues.length){let t=new(a?.Err??e)(c.issues.map(e=>w(e,o,s())));throw re(t,a?.callee),t}return c.value},O=e=>async(t,n,r,i)=>{let a=r?{...r,async:!0}:{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new(i?.Err??e)(o.issues.map(e=>w(e,a,s())));throw re(t,i?.callee),t}return o.value},k=e=>(t,n,r)=>{let a=r?{...r,async:!1}:{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new i;return o.issues.length?{success:!1,error:new(e??ye)(o.issues.map(e=>w(e,a,s())))}:{success:!0,data:o.value}},Ce=k(be),A=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>w(e,i,s())))}:{success:!0,data:a.value}},we=A(be),Te=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return D(e)(t,n,i)},Ee=e=>(t,n,r)=>D(e)(t,n,r),De=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return O(e)(t,n,i)},Oe=e=>async(t,n,r)=>O(e)(t,n,r),ke=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return k(e)(t,n,i)},Ae=e=>(t,n,r)=>k(e)(t,n,r),je=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return A(e)(t,n,i)},Me=e=>async(t,n,r)=>A(e)(t,n,r),Ne=/^[cC][0-9a-z]{6,}$/,Pe=/^[0-9a-z]+$/,Fe=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Ie=/^[0-9a-vA-V]{20}$/,Le=/^[A-Za-z0-9]{27}$/,Re=/^[a-zA-Z0-9_-]{21}$/,ze=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Be=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ve=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,He=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Ue=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;function We(){return new RegExp(Ue,`u`)}var Ge=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ke=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,qe=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Je=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ye=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Xe=/^[A-Za-z0-9_-]*$/,Ze=/^https?$/,Qe=/^\+[1-9]\d{6,14}$/,$e=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,et=RegExp(`^${$e}$`);function tt(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function nt(e){return RegExp(`^${tt(e)}$`)}function rt(e){let t=tt({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${$e}T(?:${r})$`)}var it=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},at=/^-?\d+$/,ot=/^-?\d+(?:\.\d+)?$/,st=/^(?:true|false)$/i,ct=/^[^A-Z]*$/,lt=/^[^a-z]*$/,j=r(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),ut={number:`number`,bigint:`bigint`,object:`date`},dt=r(`$ZodCheckLessThan`,(e,t)=>{j.init(e,t);let n=ut[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),ft=r(`$ZodCheckGreaterThan`,(e,t)=>{j.init(e,t);let n=ut[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),pt=r(`$ZodCheckMultipleOf`,(e,t)=>{j.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):p(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),mt=r(`$ZodCheckNumberFormat`,(e,t)=>{j.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=ce[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=at)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),ht=r(`$ZodCheckMaxLength`,(e,t)=>{var n;j.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!d(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=T(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),gt=r(`$ZodCheckMinLength`,(e,t)=>{var n;j.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!d(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=T(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),_t=r(`$ZodCheckLengthEquals`,(e,t)=>{var n;j.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!d(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=T(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),M=r(`$ZodCheckStringFormat`,(e,t)=>{var n,r;j.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),vt=r(`$ZodCheckRegex`,(e,t)=>{M.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),yt=r(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=ct,M.init(e,t)}),bt=r(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=lt,M.init(e,t)}),xt=r(`$ZodCheckIncludes`,(e,t)=>{j.init(e,t);let n=y(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),St=r(`$ZodCheckStartsWith`,(e,t)=>{j.init(e,t);let n=RegExp(`^${y(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Ct=r(`$ZodCheckEndsWith`,(e,t)=>{j.init(e,t);let n=RegExp(`.*${y(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),wt=r(`$ZodCheckOverwrite`,(e,t)=>{j.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),Tt=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
2
|
+
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
|
|
3
|
+
`))}},Et={major:4,minor:4,patch:3},N=r(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Et;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=S(e),a;for(let o of t){if(o._zod.def.when){if(ge(e)||!o._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,s=o._zod.check(e);if(s instanceof Promise&&n?.async===!1)throw new i;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,e.issues.length!==t&&(r||=S(e,t))});else{if(e.issues.length===t)continue;r||=S(e,t)}}return a?a.then(()=>e):e},n=(n,a,o)=>{if(S(n))return n.aborted=!0,n;let s=t(a,r,o);if(s instanceof Promise){if(o.async===!1)throw new i;return s.then(t=>e._zod.parse(t,o))}return e._zod.parse(s,o)};e._zod.run=(a,o)=>{if(o.skipChecks)return e._zod.parse(a,o);if(o.direction===`backward`){let t=e._zod.parse({value:a.value,issues:[]},{...o,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,a,o)):n(t,a,o)}let s=e._zod.parse(a,o);if(s instanceof Promise){if(o.async===!1)throw new i;return s.then(e=>t(e,r,o))}return t(s,r,o)}}m(e,`~standard`,()=>({validate:t=>{try{let n=Ce(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return we(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),P=r(`$ZodString`,(e,t)=>{N.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??it(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),F=r(`$ZodStringFormat`,(e,t)=>{M.init(e,t),P.init(e,t)}),Dt=r(`$ZodGUID`,(e,t)=>{t.pattern??=Be,F.init(e,t)}),Ot=r(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=Ve(e)}else t.pattern??=Ve();F.init(e,t)}),kt=r(`$ZodEmail`,(e,t)=>{t.pattern??=He,F.init(e,t)}),At=r(`$ZodURL`,(e,t)=>{F.init(e,t),e._zod.check=n=>{try{let r=n.value.trim();if(!t.normalize&&t.protocol?.source===Ze.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}let i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),jt=r(`$ZodEmoji`,(e,t)=>{t.pattern??=We(),F.init(e,t)}),Mt=r(`$ZodNanoID`,(e,t)=>{t.pattern??=Re,F.init(e,t)}),Nt=r(`$ZodCUID`,(e,t)=>{t.pattern??=Ne,F.init(e,t)}),Pt=r(`$ZodCUID2`,(e,t)=>{t.pattern??=Pe,F.init(e,t)}),Ft=r(`$ZodULID`,(e,t)=>{t.pattern??=Fe,F.init(e,t)}),It=r(`$ZodXID`,(e,t)=>{t.pattern??=Ie,F.init(e,t)}),Lt=r(`$ZodKSUID`,(e,t)=>{t.pattern??=Le,F.init(e,t)}),Rt=r(`$ZodISODateTime`,(e,t)=>{t.pattern??=rt(t),F.init(e,t)}),zt=r(`$ZodISODate`,(e,t)=>{t.pattern??=et,F.init(e,t)}),Bt=r(`$ZodISOTime`,(e,t)=>{t.pattern??=nt(t),F.init(e,t)}),Vt=r(`$ZodISODuration`,(e,t)=>{t.pattern??=ze,F.init(e,t)}),Ht=r(`$ZodIPv4`,(e,t)=>{t.pattern??=Ge,F.init(e,t),e._zod.bag.format=`ipv4`}),Ut=r(`$ZodIPv6`,(e,t)=>{t.pattern??=Ke,F.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Wt=r(`$ZodCIDRv4`,(e,t)=>{t.pattern??=qe,F.init(e,t)}),Gt=r(`$ZodCIDRv6`,(e,t)=>{t.pattern??=Je,F.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}});function Kt(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var qt=r(`$ZodBase64`,(e,t)=>{t.pattern??=Ye,F.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Kt(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}});function Jt(e){if(!Xe.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Kt(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var Yt=r(`$ZodBase64URL`,(e,t)=>{t.pattern??=Xe,F.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{Jt(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Xt=r(`$ZodE164`,(e,t)=>{t.pattern??=Qe,F.init(e,t)});function Zt(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var Qt=r(`$ZodJWT`,(e,t)=>{F.init(e,t),e._zod.check=n=>{Zt(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),$t=r(`$ZodNumber`,(e,t)=>{N.init(e,t),e._zod.pattern=e._zod.bag.pattern??ot,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),en=r(`$ZodNumberFormat`,(e,t)=>{mt.init(e,t),$t.init(e,t)}),tn=r(`$ZodBoolean`,(e,t)=>{N.init(e,t),e._zod.pattern=st,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),nn=r(`$ZodUnknown`,(e,t)=>{N.init(e,t),e._zod.parse=e=>e}),rn=r(`$ZodNever`,(e,t)=>{N.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function an(e,t,n){e.issues.length&&t.issues.push(..._e(n,e.issues)),t.value[n]=e.value}var on=r(`$ZodArray`,(e,t)=>{N.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>an(t,n,e))):an(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}});function I(e,t,n,r,i,a){let o=n in r;if(e.issues.length){if(i&&a&&!o)return;t.issues.push(..._e(n,e.issues))}if(!o&&!i){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?o&&(t.value[n]=void 0):t.value[n]=e.value}function sn(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=se(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function cn(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optin===`optional`,d=c.optout===`optional`;for(let i in t){if(i===`__proto__`||s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>I(e,n,i,t,u,d))):I(a,n,i,t,u,d)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}var ln=r(`$ZodObject`,(e,t)=>{if(N.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=u(()=>sn(t));m(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=_,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optin===`optional`,i=n._zod.optout===`optional`,a=n._zod.run({value:s[e],issues:[]},o);a instanceof Promise?c.push(a.then(n=>I(n,t,e,s,r,i))):I(a,t,e,s,r,i)}return i?cn(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),un=r(`$ZodObjectJIT`,(e,t)=>{ln.init(e,t);let n=e._zod.parse,r=u(()=>sn(t)),i=e=>{let t=new Tt([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=te(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=te(r),s=e[r],c=s?._zod?.optin===`optional`,l=s?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),c&&l?t.write(`
|
|
4
|
+
if (${n}.issues.length) {
|
|
5
|
+
if (${o} in input) {
|
|
6
|
+
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
7
|
+
...iss,
|
|
8
|
+
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
9
|
+
})));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (${n}.value === undefined) {
|
|
14
|
+
if (${o} in input) {
|
|
15
|
+
newResult[${o}] = undefined;
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
newResult[${o}] = ${n}.value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
`):c?t.write(`
|
|
22
|
+
if (${n}.issues.length) {
|
|
23
|
+
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
24
|
+
...iss,
|
|
25
|
+
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
26
|
+
})));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (${n}.value === undefined) {
|
|
30
|
+
if (${o} in input) {
|
|
31
|
+
newResult[${o}] = undefined;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
newResult[${o}] = ${n}.value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
`):t.write(`
|
|
38
|
+
const ${n}_present = ${o} in input;
|
|
39
|
+
if (${n}.issues.length) {
|
|
40
|
+
payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
|
|
41
|
+
...iss,
|
|
42
|
+
path: iss.path ? [${o}, ...iss.path] : [${o}]
|
|
43
|
+
})));
|
|
44
|
+
}
|
|
45
|
+
if (!${n}_present && !${n}.issues.length) {
|
|
46
|
+
payload.issues.push({
|
|
47
|
+
code: "invalid_type",
|
|
48
|
+
expected: "nonoptional",
|
|
49
|
+
input: undefined,
|
|
50
|
+
path: [${o}]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (${n}_present) {
|
|
55
|
+
if (${n}.value === undefined) {
|
|
56
|
+
newResult[${o}] = undefined;
|
|
57
|
+
} else {
|
|
58
|
+
newResult[${o}] = ${n}.value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
`)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,s=_,c=!o.jitless,l=c&&ie.value,d=t.catchall,f;e._zod.parse=(o,u)=>{f??=r.value;let p=o.value;return s(p)?c&&l&&u?.async===!1&&u.jitless!==!0?(a||=i(t.shape),o=a(o,u),d?cn([],p,o,u,f,e):o):n(o,u):(o.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),o)}});function dn(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!S(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>w(e,r,s())))}),t)}var fn=r(`$ZodUnion`,(e,t)=>{N.init(e,t),m(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),m(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),m(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),m(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>f(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>dn(t,r,e,i)):dn(o,r,e,i)}}),pn=r(`$ZodIntersection`,(e,t)=>{N.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>mn(e,t,n)):mn(e,i,a)}});function L(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(v(e)&&v(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=L(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=L(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function mn(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),S(e))return e;let o=L(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}var hn=r(`$ZodEnum`,(e,t)=>{N.init(e,t);let n=c(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>oe.has(typeof e)).map(e=>typeof e==`string`?y(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),gn=r(`$ZodTransform`,(e,t)=>{N.init(e,t),e._zod.optin=`optional`,e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new a(e.constructor.name);let o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(e=>(n.value=e,n.fallback=!0,n));if(o instanceof Promise)throw new i;return n.value=o,n.fallback=!0,n}});function _n(e,t){return t===void 0&&(e.issues.length||e.fallback)?{issues:[],value:void 0}:e}var vn=r(`$ZodOptional`,(e,t)=>{N.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,m(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),m(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${f(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=e.value,i=t.innerType._zod.run(e,n);return i instanceof Promise?i.then(e=>_n(e,r)):_n(i,r)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),yn=r(`$ZodExactOptional`,(e,t)=>{vn.init(e,t),m(e._zod,`values`,()=>t.innerType._zod.values),m(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),bn=r(`$ZodNullable`,(e,t)=>{N.init(e,t),m(e._zod,`optin`,()=>t.innerType._zod.optin),m(e._zod,`optout`,()=>t.innerType._zod.optout),m(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${f(e.source)}|null)$`):void 0}),m(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),xn=r(`$ZodDefault`,(e,t)=>{N.init(e,t),e._zod.optin=`optional`,m(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Sn(e,t)):Sn(r,t)}});function Sn(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Cn=r(`$ZodPrefault`,(e,t)=>{N.init(e,t),e._zod.optin=`optional`,m(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),wn=r(`$ZodNonOptional`,(e,t)=>{N.init(e,t),m(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Tn(t,e)):Tn(i,e)}});function Tn(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}var En=r(`$ZodCatch`,(e,t)=>{N.init(e,t),e._zod.optin=`optional`,m(e._zod,`optout`,()=>t.innerType._zod.optout),m(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>w(e,n,s()))},input:e.value}),e.issues=[],e.fallback=!0),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>w(e,n,s()))},input:e.value}),e.issues=[],e.fallback=!0),e)}}),Dn=r(`$ZodPipe`,(e,t)=>{N.init(e,t),m(e._zod,`values`,()=>t.in._zod.values),m(e._zod,`optin`,()=>t.in._zod.optin),m(e._zod,`optout`,()=>t.out._zod.optout),m(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>R(e,t.in,n)):R(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>R(e,t.out,n)):R(r,t.out,n)}});function R(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues,fallback:e.fallback},n)}var On=r(`$ZodReadonly`,(e,t)=>{N.init(e,t),m(e._zod,`propValues`,()=>t.innerType._zod.propValues),m(e._zod,`values`,()=>t.innerType._zod.values),m(e._zod,`optin`,()=>t.innerType?._zod?.optin),m(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(kn):kn(r)}});function kn(e){return e.value=Object.freeze(e.value),e}var An=r(`$ZodCustom`,(e,t)=>{j.init(e,t),N.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>jn(t,n,r,e));jn(i,n,r,e)}});function jn(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(E(e))}}var Mn,Nn=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function Pn(){return new Nn}(Mn=globalThis).__zod_globalRegistry??(Mn.__zod_globalRegistry=Pn());var z=globalThis.__zod_globalRegistry;function Fn(e,t){return new e({type:`string`,...x(t)})}function In(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...x(t)})}function Ln(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...x(t)})}function Rn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...x(t)})}function zn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...x(t)})}function Bn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...x(t)})}function Vn(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...x(t)})}function Hn(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...x(t)})}function Un(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...x(t)})}function Wn(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...x(t)})}function Gn(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...x(t)})}function Kn(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...x(t)})}function qn(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...x(t)})}function Jn(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...x(t)})}function Yn(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...x(t)})}function Xn(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...x(t)})}function Zn(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...x(t)})}function Qn(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...x(t)})}function $n(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...x(t)})}function er(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...x(t)})}function tr(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...x(t)})}function nr(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...x(t)})}function rr(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...x(t)})}function ir(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...x(t)})}function ar(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...x(t)})}function or(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...x(t)})}function sr(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...x(t)})}function cr(e,t){return new e({type:`number`,checks:[],...x(t)})}function lr(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...x(t)})}function ur(e,t){return new e({type:`boolean`,...x(t)})}function dr(e){return new e({type:`unknown`})}function fr(e,t){return new e({type:`never`,...x(t)})}function pr(e,t){return new dt({check:`less_than`,...x(t),value:e,inclusive:!1})}function B(e,t){return new dt({check:`less_than`,...x(t),value:e,inclusive:!0})}function mr(e,t){return new ft({check:`greater_than`,...x(t),value:e,inclusive:!1})}function V(e,t){return new ft({check:`greater_than`,...x(t),value:e,inclusive:!0})}function hr(e,t){return new pt({check:`multiple_of`,...x(t),value:e})}function gr(e,t){return new ht({check:`max_length`,...x(t),maximum:e})}function H(e,t){return new gt({check:`min_length`,...x(t),minimum:e})}function _r(e,t){return new _t({check:`length_equals`,...x(t),length:e})}function vr(e,t){return new vt({check:`string_format`,format:`regex`,...x(t),pattern:e})}function yr(e){return new yt({check:`string_format`,format:`lowercase`,...x(e)})}function br(e){return new bt({check:`string_format`,format:`uppercase`,...x(e)})}function xr(e,t){return new xt({check:`string_format`,format:`includes`,...x(t),includes:e})}function Sr(e,t){return new St({check:`string_format`,format:`starts_with`,...x(t),prefix:e})}function Cr(e,t){return new Ct({check:`string_format`,format:`ends_with`,...x(t),suffix:e})}function U(e){return new wt({check:`overwrite`,tx:e})}function wr(e){return U(t=>t.normalize(e))}function Tr(){return U(e=>e.trim())}function Er(){return U(e=>e.toLowerCase())}function Dr(){return U(e=>e.toUpperCase())}function Or(){return U(e=>ne(e))}function kr(e,t,n){return new e({type:`array`,element:t,...x(n)})}function Ar(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...x(n)})}function jr(e,t){let n=Mr(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(E(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=t.value,r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(E(r))}},e(t.value,t)),t);return n}function Mr(e,t){let n=new j({check:`custom`,...x(t)});return n._zod.check=e,n}function Nr(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??z,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function W(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,W(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&G(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Pr(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
63
|
+
|
|
64
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function Fr(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e===`$ref`||e===`allOf`||e in a||delete i[e];if(s.$ref&&n.def)for(let e in i)e===`$ref`||e===`allOf`||e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e===`$ref`||e===`allOf`||e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,o[e.defId]=e.def)}e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:K(t,`input`,e.processors),output:K(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function G(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return G(r.element,n);if(r.type===`set`)return G(r.valueType,n);if(r.type===`lazy`)return G(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return G(r.innerType,n);if(r.type===`intersection`)return G(r.left,n)||G(r.right,n);if(r.type===`record`||r.type===`map`)return G(r.keyType,n)||G(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:G(r.in,n)||G(r.out,n);if(r.type===`object`){for(let e in r.shape)if(G(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(G(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(G(e,n))return!0;return!!(r.rest&&G(r.rest,n))}return!1}var Ir=(e,t={})=>n=>{let r=Nr({...n,processors:t});return W(e,r),Pr(r,e),Fr(r,e)},K=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Nr({...i??{},target:a,io:t,processors:n});return W(e,o),Pr(o,e),Fr(o,e)},Lr={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Rr=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Lr[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},zr=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;typeof s==`string`&&s.includes(`int`)?i.type=`integer`:i.type=`number`;let d=typeof u==`number`&&u>=(a??-1/0),f=typeof l==`number`&&l<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;d?p?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l:typeof o==`number`&&(i.maximum=o),typeof c==`number`&&(i.multipleOf=c)},Br=(e,t,n,r)=>{n.type=`boolean`},Vr=(e,t,n,r)=>{n.not={}},Hr=(e,t,n,r)=>{let i=e._zod.def,a=c(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Ur=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Wr=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Gr=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=W(a.element,t,{...r,path:[...r.path,`items`]})},Kr=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=W(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=W(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},qr=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>W(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Jr=(e,t,n,r)=>{let i=e._zod.def,a=W(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=W(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Yr=(e,t,n,r)=>{let i=e._zod.def,a=W(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Xr=(e,t,n,r)=>{let i=e._zod.def;W(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Zr=(e,t,n,r)=>{let i=e._zod.def;W(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Qr=(e,t,n,r)=>{let i=e._zod.def;W(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},$r=(e,t,n,r)=>{let i=e._zod.def;W(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},ei=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;W(o,t,r);let s=t.seen.get(e);s.ref=o},ti=(e,t,n,r)=>{let i=e._zod.def;W(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},ni=(e,t,n,r)=>{let i=e._zod.def;W(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ri=r(`ZodISODateTime`,(e,t)=>{Rt.init(e,t),Z.init(e,t)});function ii(e){return ir(ri,e)}var ai=r(`ZodISODate`,(e,t)=>{zt.init(e,t),Z.init(e,t)});function oi(e){return ar(ai,e)}var si=r(`ZodISOTime`,(e,t)=>{Bt.init(e,t),Z.init(e,t)});function ci(e){return or(si,e)}var li=r(`ZodISODuration`,(e,t)=>{Vt.init(e,t),Z.init(e,t)});function ui(e){return sr(li,e)}var q=r(`ZodError`,(e,t)=>{ye.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Se(e,t)},flatten:{value:t=>xe(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,l,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,l,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),di=D(q),fi=O(q),pi=k(q),mi=A(q),hi=Te(q),gi=Ee(q),_i=De(q),vi=Oe(q),yi=ke(q),bi=Ae(q),xi=je(q),Si=Me(q),Ci=new WeakMap;function J(e,t,n){let r=Object.getPrototypeOf(e),i=Ci.get(r);if(i||(i=new Set,Ci.set(r,i)),!i.has(t)){i.add(t);for(let e in n){let t=n[e];Object.defineProperty(r,e,{configurable:!0,enumerable:!1,get(){let n=t.bind(this);return Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:n}),n},set(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,enumerable:!0,value:t})}})}}}var Y=r(`ZodType`,(e,t)=>(N.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:K(e,`input`),output:K(e,`output`)}}),e.toJSONSchema=Ir(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.parse=(t,n)=>di(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>pi(e,t,n),e.parseAsync=async(t,n)=>fi(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>mi(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>hi(e,t,n),e.decode=(t,n)=>gi(e,t,n),e.encodeAsync=async(t,n)=>_i(e,t,n),e.decodeAsync=async(t,n)=>vi(e,t,n),e.safeEncode=(t,n)=>yi(e,t,n),e.safeDecode=(t,n)=>bi(e,t,n),e.safeEncodeAsync=async(t,n)=>xi(e,t,n),e.safeDecodeAsync=async(t,n)=>Si(e,t,n),J(e,`ZodType`,{check(...e){let t=this.def;return this.clone(g(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return b(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Aa(e,t))},superRefine(e,t){return this.check(ja(e,t))},overwrite(e){return this.check(U(e))},optional(){return fa(this)},exactOptional(){return ma(this)},nullable(){return ga(this)},nullish(){return fa(ga(this))},nonoptional(e){return Sa(this,e)},array(){return $(this)},or(e){return ia([this,e])},and(e){return oa(this,e)},transform(e){return Ea(this,ua(e))},default(e){return va(this,e)},prefault(e){return ba(this,e)},catch(e){return wa(this,e)},pipe(e){return Ea(this,e)},readonly(){return Oa(this)},describe(e){let t=this.clone();return z.add(t,{description:e}),t},meta(...e){if(e.length===0)return z.get(this);let t=this.clone();return z.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e){return e(this)}}),Object.defineProperty(e,"description",{get(){return z.get(e)?.description},configurable:!0}),e)),wi=r(`_ZodString`,(e,t)=>{P.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Rr(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,J(e,`_ZodString`,{regex(...e){return this.check(vr(...e))},includes(...e){return this.check(xr(...e))},startsWith(...e){return this.check(Sr(...e))},endsWith(...e){return this.check(Cr(...e))},min(...e){return this.check(H(...e))},max(...e){return this.check(gr(...e))},length(...e){return this.check(_r(...e))},nonempty(...e){return this.check(H(1,...e))},lowercase(e){return this.check(yr(e))},uppercase(e){return this.check(br(e))},trim(){return this.check(Tr())},normalize(...e){return this.check(wr(...e))},toLowerCase(){return this.check(Er())},toUpperCase(){return this.check(Dr())},slugify(){return this.check(Or())}})}),Ti=r(`ZodString`,(e,t)=>{P.init(e,t),wi.init(e,t),e.email=t=>e.check(In(Ei,t)),e.url=t=>e.check(Hn(Oi,t)),e.jwt=t=>e.check(rr(Ui,t)),e.emoji=t=>e.check(Un(ki,t)),e.guid=t=>e.check(Ln(Di,t)),e.uuid=t=>e.check(Rn(Q,t)),e.uuidv4=t=>e.check(zn(Q,t)),e.uuidv6=t=>e.check(Bn(Q,t)),e.uuidv7=t=>e.check(Vn(Q,t)),e.nanoid=t=>e.check(Wn(Ai,t)),e.guid=t=>e.check(Ln(Di,t)),e.cuid=t=>e.check(Gn(ji,t)),e.cuid2=t=>e.check(Kn(Mi,t)),e.ulid=t=>e.check(qn(Ni,t)),e.base64=t=>e.check(er(Bi,t)),e.base64url=t=>e.check(tr(Vi,t)),e.xid=t=>e.check(Jn(Pi,t)),e.ksuid=t=>e.check(Yn(Fi,t)),e.ipv4=t=>e.check(Xn(Ii,t)),e.ipv6=t=>e.check(Zn(Li,t)),e.cidrv4=t=>e.check(Qn(Ri,t)),e.cidrv6=t=>e.check($n(zi,t)),e.e164=t=>e.check(nr(Hi,t)),e.datetime=t=>e.check(ii(t)),e.date=t=>e.check(oi(t)),e.time=t=>e.check(ci(t)),e.duration=t=>e.check(ui(t))});function X(e){return Fn(Ti,e)}var Z=r(`ZodStringFormat`,(e,t)=>{F.init(e,t),wi.init(e,t)}),Ei=r(`ZodEmail`,(e,t)=>{kt.init(e,t),Z.init(e,t)}),Di=r(`ZodGUID`,(e,t)=>{Dt.init(e,t),Z.init(e,t)}),Q=r(`ZodUUID`,(e,t)=>{Ot.init(e,t),Z.init(e,t)}),Oi=r(`ZodURL`,(e,t)=>{At.init(e,t),Z.init(e,t)}),ki=r(`ZodEmoji`,(e,t)=>{jt.init(e,t),Z.init(e,t)}),Ai=r(`ZodNanoID`,(e,t)=>{Mt.init(e,t),Z.init(e,t)}),ji=r(`ZodCUID`,(e,t)=>{Nt.init(e,t),Z.init(e,t)}),Mi=r(`ZodCUID2`,(e,t)=>{Pt.init(e,t),Z.init(e,t)}),Ni=r(`ZodULID`,(e,t)=>{Ft.init(e,t),Z.init(e,t)}),Pi=r(`ZodXID`,(e,t)=>{It.init(e,t),Z.init(e,t)}),Fi=r(`ZodKSUID`,(e,t)=>{Lt.init(e,t),Z.init(e,t)}),Ii=r(`ZodIPv4`,(e,t)=>{Ht.init(e,t),Z.init(e,t)}),Li=r(`ZodIPv6`,(e,t)=>{Ut.init(e,t),Z.init(e,t)}),Ri=r(`ZodCIDRv4`,(e,t)=>{Wt.init(e,t),Z.init(e,t)}),zi=r(`ZodCIDRv6`,(e,t)=>{Gt.init(e,t),Z.init(e,t)}),Bi=r(`ZodBase64`,(e,t)=>{qt.init(e,t),Z.init(e,t)}),Vi=r(`ZodBase64URL`,(e,t)=>{Yt.init(e,t),Z.init(e,t)}),Hi=r(`ZodE164`,(e,t)=>{Xt.init(e,t),Z.init(e,t)}),Ui=r(`ZodJWT`,(e,t)=>{Qt.init(e,t),Z.init(e,t)}),Wi=r(`ZodNumber`,(e,t)=>{$t.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zr(e,t,n,r),J(e,`ZodNumber`,{gt(e,t){return this.check(mr(e,t))},gte(e,t){return this.check(V(e,t))},min(e,t){return this.check(V(e,t))},lt(e,t){return this.check(pr(e,t))},lte(e,t){return this.check(B(e,t))},max(e,t){return this.check(B(e,t))},int(e){return this.check(qi(e))},safe(e){return this.check(qi(e))},positive(e){return this.check(mr(0,e))},nonnegative(e){return this.check(V(0,e))},negative(e){return this.check(pr(0,e))},nonpositive(e){return this.check(B(0,e))},multipleOf(e,t){return this.check(hr(e,t))},step(e,t){return this.check(hr(e,t))},finite(){return this}});let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function Gi(e){return cr(Wi,e)}var Ki=r(`ZodNumberFormat`,(e,t)=>{en.init(e,t),Wi.init(e,t)});function qi(e){return lr(Ki,e)}var Ji=r(`ZodBoolean`,(e,t)=>{tn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Br(e,t,n,r)});function Yi(e){return ur(Ji,e)}var Xi=r(`ZodUnknown`,(e,t)=>{nn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function Zi(){return dr(Xi)}var Qi=r(`ZodNever`,(e,t)=>{rn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vr(e,t,n,r)});function $i(e){return fr(Qi,e)}var ea=r(`ZodArray`,(e,t)=>{on.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gr(e,t,n,r),e.element=t.element,J(e,`ZodArray`,{min(e,t){return this.check(H(e,t))},nonempty(e){return this.check(H(1,e))},max(e,t){return this.check(gr(e,t))},length(e,t){return this.check(_r(e,t))},unwrap(){return this.element}})});function $(e,t){return kr(ea,e,t)}var ta=r(`ZodObject`,(e,t)=>{un.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kr(e,t,n,r),m(e,`shape`,()=>t.shape),J(e,`ZodObject`,{keyof(){return ca(Object.keys(this._zod.def.shape))},catchall(e){return this.clone({...this._zod.def,catchall:e})},passthrough(){return this.clone({...this._zod.def,catchall:Zi()})},loose(){return this.clone({...this._zod.def,catchall:Zi()})},strict(){return this.clone({...this._zod.def,catchall:$i()})},strip(){return this.clone({...this._zod.def,catchall:void 0})},extend(e){return de(this,e)},safeExtend(e){return fe(this,e)},merge(e){return pe(this,e)},pick(e){return le(this,e)},omit(e){return ue(this,e)},partial(...e){return me(da,this,e[0])},required(...e){return he(xa,this,e[0])}})});function na(e,t){return new ta({type:`object`,shape:e??{},...x(t)})}var ra=r(`ZodUnion`,(e,t)=>{fn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qr(e,t,n,r),e.options=t.options});function ia(e,t){return new ra({type:`union`,options:e,...x(t)})}var aa=r(`ZodIntersection`,(e,t)=>{pn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jr(e,t,n,r)});function oa(e,t){return new aa({type:`intersection`,left:e,right:t})}var sa=r(`ZodEnum`,(e,t)=>{hn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hr(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new sa({...t,checks:[],...x(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new sa({...t,checks:[],...x(r),entries:i})}});function ca(e,t){return new sa({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...x(t)})}var la=r(`ZodTransform`,(e,t)=>{gn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wr(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new a(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(E(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(E(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n.fallback=!0,n)):(n.value=i,n.fallback=!0,n)}});function ua(e){return new la({type:`transform`,transform:e})}var da=r(`ZodOptional`,(e,t)=>{vn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ni(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function fa(e){return new da({type:`optional`,innerType:e})}var pa=r(`ZodExactOptional`,(e,t)=>{yn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ni(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ma(e){return new pa({type:`optional`,innerType:e})}var ha=r(`ZodNullable`,(e,t)=>{bn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yr(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ga(e){return new ha({type:`nullable`,innerType:e})}var _a=r(`ZodDefault`,(e,t)=>{xn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zr(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function va(e,t){return new _a({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ae(t)}})}var ya=r(`ZodPrefault`,(e,t)=>{Cn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qr(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function ba(e,t){return new ya({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ae(t)}})}var xa=r(`ZodNonOptional`,(e,t)=>{wn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xr(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Sa(e,t){return new xa({type:`nonoptional`,innerType:e,...x(t)})}var Ca=r(`ZodCatch`,(e,t)=>{En.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$r(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function wa(e,t){return new Ca({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}var Ta=r(`ZodPipe`,(e,t)=>{Dn.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ei(e,t,n,r),e.in=t.in,e.out=t.out});function Ea(e,t){return new Ta({type:`pipe`,in:e,out:t})}var Da=r(`ZodReadonly`,(e,t)=>{On.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ti(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Oa(e){return new Da({type:`readonly`,innerType:e})}var ka=r(`ZodCustom`,(e,t)=>{An.init(e,t),Y.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ur(e,t,n,r)});function Aa(e,t={}){return Ar(ka,e,t)}function ja(e,t){return jr(e,t)}var Ma=na({sorts:$(na({columnId:X(),direction:ca([`asc`,`desc`])})).optional(),filters:$(na({columnId:X(),operator:ca([`eq`,`contains`,`gt`,`gte`,`lt`,`lte`,`between`,`in`]),value:ia([X(),Gi(),$(ia([X(),Gi()]))])})).optional(),grouping:$(X()).optional(),reset:Yi().optional(),explanation:X()});function Na(e){return`You are a data grid assistant. The user will describe what they want to see in the grid in natural language, and you must respond with a JSON object that controls sorting, filtering, and grouping.
|
|
65
|
+
|
|
66
|
+
Available columns:
|
|
67
|
+
${e.map(e=>` - id="${e.id}" header="${e.header}"${e.filterType?` filterType="${e.filterType}"`:``}`).join(`
|
|
68
|
+
`)}
|
|
69
|
+
|
|
70
|
+
Response format (JSON only — no markdown, no explanation outside the JSON):
|
|
71
|
+
{
|
|
72
|
+
"sorts": [{ "columnId": "<id>", "direction": "asc" | "desc" }],
|
|
73
|
+
"filters": [{ "columnId": "<id>", "operator": "eq" | "contains" | "gt" | "gte" | "lt" | "lte" | "between" | "in", "value": <string | number | array> }],
|
|
74
|
+
"grouping": ["<columnId>"],
|
|
75
|
+
"reset": false,
|
|
76
|
+
"explanation": "<one sentence describing what you did>"
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Rules:
|
|
80
|
+
- Only include fields that should change. Omit "sorts", "filters", or "grouping" if you are not changing them.
|
|
81
|
+
- Set "reset": true to clear all sorts, filters, and grouping.
|
|
82
|
+
- Only use column ids from the list above. Ignore any column the user mentions that does not exist.
|
|
83
|
+
- For "select" filterType columns, "operator" must be "eq" or "in".
|
|
84
|
+
- For "number" or "date" filterType columns, "operator" can be "gt", "gte", "lt", "lte", "between", "eq".
|
|
85
|
+
- For "text" filterType columns, "operator" must be "contains" or "eq".
|
|
86
|
+
- "between" requires value to be a two-element array: [min, max].
|
|
87
|
+
- "in" requires value to be an array of strings or numbers.
|
|
88
|
+
- Always include a concise "explanation" field.`}function Pa(e){return`Current grid state:\n${JSON.stringify(e.currentState,null,2)}\n\nUser request: ${e.prompt}`}function Fa(){return process.env.LLM_PROVIDER===`openai`?new t:new e}function Ia(e){let t=e.match(/```(?:json)?\s*([\s\S]*?)```/);return t?t[1].trim():e.trim()}var La=1e3;async function Ra(e){if(!e.prompt||typeof e.prompt!=`string`)throw Error(`Invalid request body: prompt is required`);if(e.prompt.length>La)throw Error(`Prompt exceeds maximum length of ${La} characters`);if(!Array.isArray(e.columns)||e.columns.length===0)throw Error(`Invalid request body: columns must be a non-empty array`);let t=Fa(),n=Na(e.columns),r=Pa(e),i=Ia(await t.complete(n,r)),a;try{a=JSON.parse(i)}catch{throw Error(`AI returned an invalid response. Please try again.`)}return Ma.parse(a)}exports.handleGridAiRequest=Ra;
|