@ic-reactor/candid 3.0.13-beta.0 → 3.0.14-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/dist/visitor/arguments/helpers.d.ts +5 -5
- package/dist/visitor/arguments/helpers.d.ts.map +1 -1
- package/dist/visitor/arguments/helpers.js.map +1 -1
- package/dist/visitor/arguments/index.d.ts +12 -2
- package/dist/visitor/arguments/index.d.ts.map +1 -1
- package/dist/visitor/arguments/index.js +140 -25
- package/dist/visitor/arguments/index.js.map +1 -1
- package/dist/visitor/arguments/types.d.ts +76 -419
- package/dist/visitor/arguments/types.d.ts.map +1 -1
- package/dist/visitor/constants.d.ts.map +1 -1
- package/dist/visitor/constants.js +19 -17
- package/dist/visitor/constants.js.map +1 -1
- package/dist/visitor/returns/types.d.ts +3 -4
- package/dist/visitor/returns/types.d.ts.map +1 -1
- package/dist/visitor/types.d.ts +14 -0
- package/dist/visitor/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/visitor/arguments/helpers.ts +7 -7
- package/src/visitor/arguments/index.test.ts +104 -39
- package/src/visitor/arguments/index.ts +170 -42
- package/src/visitor/arguments/schema.test.ts +114 -4
- package/src/visitor/arguments/types.ts +113 -480
- package/src/visitor/constants.ts +24 -15
- package/src/visitor/returns/index.test.ts +1 -1
- package/src/visitor/returns/types.ts +4 -27
- package/src/visitor/types.ts +45 -0
|
@@ -1,527 +1,184 @@
|
|
|
1
1
|
import type { BaseActor, FunctionName, FunctionType } from "@ic-reactor/core";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
|
|
3
|
+
import type { VisitorDataType, TextFormat, NumberFormat } from "../types";
|
|
4
|
+
export type { VisitorDataType, TextFormat, NumberFormat };
|
|
4
5
|
/**
|
|
5
6
|
* Suggested component type for rendering the field.
|
|
6
|
-
* This eliminates the need for switch statements in the frontend.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* const componentMap = {
|
|
11
|
-
* 'text-input': TextField,
|
|
12
|
-
* 'number-input': NumberField,
|
|
13
|
-
* 'boolean-checkbox': BooleanField,
|
|
14
|
-
* // ...
|
|
15
|
-
* }
|
|
16
|
-
* const Component = componentMap[field.component]
|
|
17
|
-
* return <Component field={field} />
|
|
18
|
-
* ```
|
|
19
7
|
*/
|
|
20
8
|
export type FieldComponentType = "record-container" | "tuple-container" | "variant-select" | "optional-toggle" | "vector-list" | "blob-upload" | "principal-input" | "text-input" | "number-input" | "boolean-checkbox" | "null-hidden" | "recursive-lazy" | "unknown-fallback";
|
|
21
9
|
/**
|
|
22
10
|
* Input type hints for HTML input elements.
|
|
23
|
-
* Used by primitive fields to suggest the appropriate input type.
|
|
24
11
|
*/
|
|
25
12
|
export type InputType = "text" | "number" | "checkbox" | "select" | "file" | "textarea";
|
|
26
13
|
/**
|
|
27
14
|
* Rendering hints for the UI.
|
|
28
|
-
* Eliminates the need for frontend to maintain COMPLEX_TYPES arrays.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* // Frontend no longer needs:
|
|
33
|
-
* // const COMPLEX_TYPES = ["record", "tuple", "variant", "vector", "optional"]
|
|
34
|
-
*
|
|
35
|
-
* // Instead use:
|
|
36
|
-
* if (field.renderHint.isCompound) {
|
|
37
|
-
* return <CompoundFieldRenderer field={field} />
|
|
38
|
-
* }
|
|
39
|
-
* return <PrimitiveInput field={field} />
|
|
40
|
-
* ```
|
|
41
15
|
*/
|
|
42
16
|
export interface RenderHint {
|
|
43
|
-
/** Whether this field has its own container/card styling (compound types) */
|
|
44
17
|
isCompound: boolean;
|
|
45
|
-
/** Whether this is a leaf input (primitive types) */
|
|
46
18
|
isPrimitive: boolean;
|
|
47
|
-
/** Suggested input type for HTML input elements */
|
|
48
19
|
inputType?: InputType;
|
|
49
|
-
/** Description or help text for the field (derived from Candid) */
|
|
50
20
|
description?: string;
|
|
51
21
|
}
|
|
52
22
|
/**
|
|
53
23
|
* Pre-computed HTML input props for primitive fields.
|
|
54
|
-
* Can be spread directly onto an input element.
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```tsx
|
|
58
|
-
* <input {...field.inputProps} value={value} onChange={handleChange} />
|
|
59
|
-
* ```
|
|
60
24
|
*/
|
|
61
25
|
export interface PrimitiveInputProps {
|
|
62
|
-
|
|
63
|
-
type?: "text" | "number" | "checkbox";
|
|
64
|
-
/** Placeholder text */
|
|
26
|
+
type?: "text" | "number" | "checkbox" | "email" | "url" | "tel";
|
|
65
27
|
placeholder?: string;
|
|
66
|
-
/** Minimum value for number inputs */
|
|
67
28
|
min?: string | number;
|
|
68
|
-
/** Maximum value for number inputs */
|
|
69
29
|
max?: string | number;
|
|
70
|
-
/** Step value for number inputs */
|
|
71
30
|
step?: string | number;
|
|
72
|
-
/** Pattern for text inputs */
|
|
73
31
|
pattern?: string;
|
|
74
|
-
|
|
75
|
-
inputMode?: "text" | "numeric" | "decimal";
|
|
76
|
-
/** Autocomplete hint */
|
|
32
|
+
inputMode?: "text" | "numeric" | "decimal" | "email" | "tel" | "url";
|
|
77
33
|
autoComplete?: string;
|
|
78
|
-
/** Whether to check spelling */
|
|
79
34
|
spellCheck?: boolean;
|
|
80
|
-
/** Minimum length for text inputs */
|
|
81
35
|
minLength?: number;
|
|
82
|
-
/** Maximum length for text inputs */
|
|
83
36
|
maxLength?: number;
|
|
84
37
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
type: ArgumentFieldType;
|
|
88
|
-
/** Raw label from Candid: "__arg0", "_0_" */
|
|
38
|
+
interface FieldBase<T extends VisitorDataType = VisitorDataType> {
|
|
39
|
+
type: T;
|
|
89
40
|
label: string;
|
|
90
|
-
/**
|
|
91
|
-
* Pre-formatted display label for UI rendering.
|
|
92
|
-
* Transforms raw labels into human-readable format.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* "__arg0" => "Arg 0"
|
|
96
|
-
* "_0_" => "Item 0"
|
|
97
|
-
* "created_at_time" => "Created At Time"
|
|
98
|
-
*/
|
|
99
41
|
displayLabel: string;
|
|
100
|
-
/**
|
|
101
|
-
* Form field name path for binding.
|
|
102
|
-
* Uses bracket notation for array indices: `[0]`, `args[0].owner`, `tags[1]`
|
|
103
|
-
* Compatible with TanStack Form's `form.Field` name prop.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```tsx
|
|
107
|
-
* <form.Field name={field.name}>
|
|
108
|
-
* {(fieldApi) => <input {...} />}
|
|
109
|
-
* </form.Field>
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
42
|
name: string;
|
|
113
|
-
/**
|
|
114
|
-
* Suggested component type for rendering this field.
|
|
115
|
-
* Eliminates the need for switch statements in the frontend.
|
|
116
|
-
*/
|
|
117
43
|
component: FieldComponentType;
|
|
118
|
-
/**
|
|
119
|
-
* Rendering hints for UI strategy.
|
|
120
|
-
* Use this to determine if the field needs a container or is a simple input.
|
|
121
|
-
*/
|
|
122
44
|
renderHint: RenderHint;
|
|
123
|
-
/** Zod schema for field validation */
|
|
124
45
|
schema: z.ZodTypeAny;
|
|
125
|
-
|
|
126
|
-
defaultValue:
|
|
127
|
-
|
|
128
|
-
|
|
46
|
+
candidType: string;
|
|
47
|
+
defaultValue: unknown;
|
|
48
|
+
}
|
|
49
|
+
export interface BlobLimits {
|
|
50
|
+
maxHexBytes: number;
|
|
51
|
+
maxFileBytes: number;
|
|
52
|
+
maxHexDisplayLength: number;
|
|
53
|
+
}
|
|
54
|
+
export interface BlobValidationResult {
|
|
55
|
+
valid: boolean;
|
|
56
|
+
error?: string;
|
|
129
57
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
fields: Field[];
|
|
134
|
-
/** Map of field label to its metadata for quick lookup */
|
|
135
|
-
fieldMap: Map<string, Field>;
|
|
58
|
+
interface RecordExtras {
|
|
59
|
+
fields: FieldNode[];
|
|
60
|
+
defaultValue: Record<string, unknown>;
|
|
136
61
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/** All variant option fields */
|
|
140
|
-
fields: Field[];
|
|
141
|
-
/** List of variant option names */
|
|
142
|
-
options: string[];
|
|
143
|
-
/** Default selected option */
|
|
62
|
+
interface VariantExtras {
|
|
63
|
+
fields: FieldNode[];
|
|
144
64
|
defaultOption: string;
|
|
145
|
-
|
|
146
|
-
optionMap: Map<string, Field>;
|
|
147
|
-
/**
|
|
148
|
-
* Get default value for a specific option.
|
|
149
|
-
* Useful when switching between variant options.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```tsx
|
|
153
|
-
* const handleOptionChange = (newOption: string) => {
|
|
154
|
-
* const newDefault = field.getOptionDefault(newOption)
|
|
155
|
-
* fieldApi.handleChange(newDefault)
|
|
156
|
-
* }
|
|
157
|
-
* ```
|
|
158
|
-
*/
|
|
65
|
+
defaultValue: Record<string, unknown>;
|
|
159
66
|
getOptionDefault: (option: string) => Record<string, unknown>;
|
|
160
|
-
|
|
161
|
-
* Get the field for a specific option.
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```tsx
|
|
165
|
-
* const transferField = field.getField("Transfer")
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
getField: (option: string) => Field;
|
|
169
|
-
/**
|
|
170
|
-
* Get the currently selected option from a value.
|
|
171
|
-
* Returns the first valid key found, or the default option.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```tsx
|
|
175
|
-
* const selectedOption = field.getSelectedOption(currentValue)
|
|
176
|
-
* // { Transfer: {...} } => "Transfer"
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
67
|
+
getField: (option: string) => FieldNode;
|
|
179
68
|
getSelectedOption: (value: Record<string, unknown>) => string;
|
|
180
|
-
|
|
181
|
-
* Get the selected field from a value.
|
|
182
|
-
* Combines getSelectedOption and getField for convenience.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* ```tsx
|
|
186
|
-
* // Current (verbose):
|
|
187
|
-
* const validKeys = Object.keys(currentValue).filter(k => field.options.includes(k))
|
|
188
|
-
* const selected = validKeys[0] ?? field.options[0]
|
|
189
|
-
* const selectedIndex = Math.max(0, field.options.indexOf(selected))
|
|
190
|
-
* const selectedField = field.fields[selectedIndex]
|
|
191
|
-
*
|
|
192
|
-
* // Proposed (simple):
|
|
193
|
-
* const selectedField = field.getSelectedField(currentValue)
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
getSelectedField: (value: Record<string, unknown>) => Field;
|
|
69
|
+
getSelectedField: (value: Record<string, unknown>) => FieldNode;
|
|
197
70
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
fields: Field[];
|
|
71
|
+
interface TupleExtras {
|
|
72
|
+
fields: FieldNode[];
|
|
73
|
+
defaultValue: unknown[];
|
|
202
74
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
innerField: Field;
|
|
207
|
-
/**
|
|
208
|
-
* Get default value when enabling the optional.
|
|
209
|
-
* Returns the inner field's default value.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```tsx
|
|
213
|
-
* const handleToggle = (enabled: boolean) => {
|
|
214
|
-
* if (enabled) {
|
|
215
|
-
* fieldApi.handleChange(field.getInnerDefault())
|
|
216
|
-
* } else {
|
|
217
|
-
* fieldApi.handleChange(null)
|
|
218
|
-
* }
|
|
219
|
-
* }
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
75
|
+
interface OptionalExtras {
|
|
76
|
+
innerField: FieldNode;
|
|
77
|
+
defaultValue: null;
|
|
222
78
|
getInnerDefault: () => unknown;
|
|
223
|
-
/**
|
|
224
|
-
* Check if a value represents an enabled optional.
|
|
225
|
-
* Returns true if the value is not null or undefined.
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* ```tsx
|
|
229
|
-
* // Current:
|
|
230
|
-
* const enabled = fieldApi.state.value !== null && typeof fieldApi.state.value !== "undefined"
|
|
231
|
-
*
|
|
232
|
-
* // Proposed:
|
|
233
|
-
* const enabled = field.isEnabled(fieldApi.state.value)
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
79
|
isEnabled: (value: unknown) => boolean;
|
|
237
80
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
itemField: Field;
|
|
242
|
-
/**
|
|
243
|
-
* Get a new item with default values.
|
|
244
|
-
* Used when adding items to the vector.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```tsx
|
|
248
|
-
* <button onClick={() => fieldApi.pushValue(field.getItemDefault())}>
|
|
249
|
-
* Add Item
|
|
250
|
-
* </button>
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
81
|
+
interface VectorExtras {
|
|
82
|
+
itemField: FieldNode;
|
|
83
|
+
defaultValue: unknown[];
|
|
253
84
|
getItemDefault: () => unknown;
|
|
254
|
-
/**
|
|
255
|
-
* Create a properly configured item field for a specific index.
|
|
256
|
-
* Handles name path and label generation.
|
|
257
|
-
*
|
|
258
|
-
* @example
|
|
259
|
-
* ```tsx
|
|
260
|
-
* // Current:
|
|
261
|
-
* renderField({
|
|
262
|
-
* ...field.itemField,
|
|
263
|
-
* label: itemLabel,
|
|
264
|
-
* name: itemFieldName
|
|
265
|
-
* })
|
|
266
|
-
*
|
|
267
|
-
* // Proposed:
|
|
268
|
-
* const itemField = field.createItemField(index, { label: itemLabel })
|
|
269
|
-
* renderField(itemField)
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
85
|
createItemField: (index: number, overrides?: {
|
|
273
86
|
label?: string;
|
|
274
|
-
}) =>
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Blob field size limits.
|
|
278
|
-
*/
|
|
279
|
-
export interface BlobLimits {
|
|
280
|
-
/** Maximum bytes when entering as hex (e.g., 512 bytes) */
|
|
281
|
-
maxHexBytes: number;
|
|
282
|
-
/** Maximum file size in bytes (e.g., 2MB ICP limit) */
|
|
283
|
-
maxFileBytes: number;
|
|
284
|
-
/** Maximum hex display length before truncation */
|
|
285
|
-
maxHexDisplayLength: number;
|
|
87
|
+
}) => FieldNode;
|
|
286
88
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
*/
|
|
290
|
-
export interface BlobValidationResult {
|
|
291
|
-
/** Whether the input is valid */
|
|
292
|
-
valid: boolean;
|
|
293
|
-
/** Error message if invalid */
|
|
294
|
-
error?: string;
|
|
295
|
-
}
|
|
296
|
-
export interface BlobField extends FieldBase<string> {
|
|
297
|
-
type: "blob";
|
|
298
|
-
/** Item field for individual bytes (nat8) */
|
|
299
|
-
itemField: Field;
|
|
300
|
-
/** Accepted input formats */
|
|
89
|
+
interface BlobExtras {
|
|
90
|
+
itemField: FieldNode;
|
|
301
91
|
acceptedFormats: ("hex" | "base64" | "file")[];
|
|
302
|
-
/** Size limits for blob input */
|
|
303
92
|
limits: BlobLimits;
|
|
304
|
-
/**
|
|
305
|
-
* Normalize hex input (remove 0x prefix, lowercase, etc.)
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* ```tsx
|
|
309
|
-
* const normalized = field.normalizeHex("0xDEADBEEF")
|
|
310
|
-
* // => "deadbeef"
|
|
311
|
-
* ```
|
|
312
|
-
*/
|
|
313
93
|
normalizeHex: (input: string) => string;
|
|
314
|
-
/**
|
|
315
|
-
* Validate blob input value.
|
|
316
|
-
*
|
|
317
|
-
* @example
|
|
318
|
-
* ```tsx
|
|
319
|
-
* const result = field.validateInput(value)
|
|
320
|
-
* if (!result.valid) {
|
|
321
|
-
* setError(result.error)
|
|
322
|
-
* }
|
|
323
|
-
* ```
|
|
324
|
-
*/
|
|
325
94
|
validateInput: (value: string | Uint8Array) => BlobValidationResult;
|
|
95
|
+
defaultValue: string;
|
|
326
96
|
}
|
|
327
|
-
|
|
328
|
-
type: "recursive";
|
|
329
|
-
/** Type name for the recursive type */
|
|
97
|
+
interface RecursiveExtras {
|
|
330
98
|
typeName: string;
|
|
331
|
-
|
|
332
|
-
extract: () => Field;
|
|
333
|
-
/**
|
|
334
|
-
* Get default value for the recursive type.
|
|
335
|
-
* Evaluates the inner type on demand.
|
|
336
|
-
*/
|
|
99
|
+
extract: () => FieldNode;
|
|
337
100
|
getInnerDefault: () => unknown;
|
|
101
|
+
defaultValue: undefined;
|
|
338
102
|
}
|
|
339
|
-
|
|
340
|
-
type: "principal";
|
|
103
|
+
interface PrincipalExtras {
|
|
341
104
|
maxLength: number;
|
|
342
105
|
minLength: number;
|
|
343
|
-
|
|
344
|
-
* Pre-computed HTML input props for direct spreading.
|
|
345
|
-
* @example
|
|
346
|
-
* ```tsx
|
|
347
|
-
* <input {...field.inputProps} value={value} onChange={handleChange} />
|
|
348
|
-
* ```
|
|
349
|
-
*/
|
|
106
|
+
format: TextFormat;
|
|
350
107
|
inputProps: PrimitiveInputProps;
|
|
108
|
+
defaultValue: string;
|
|
351
109
|
}
|
|
352
|
-
|
|
353
|
-
type: "number";
|
|
354
|
-
/**
|
|
355
|
-
* Original Candid type: nat, int, nat8, nat16, nat32, nat64, int8, int16, int32, int64, float32, float64
|
|
356
|
-
*/
|
|
357
|
-
candidType: string;
|
|
358
|
-
/** Whether this is an unsigned type */
|
|
110
|
+
interface NumberExtras {
|
|
359
111
|
unsigned: boolean;
|
|
360
|
-
/** Whether this is a floating point type */
|
|
361
112
|
isFloat: boolean;
|
|
362
|
-
/** Bit width if applicable (8, 16, 32, 64, or undefined for unbounded) */
|
|
363
113
|
bits?: number;
|
|
364
|
-
/** Minimum value constraint (for bounded types) */
|
|
365
114
|
min?: string;
|
|
366
|
-
/** Maximum value constraint (for bounded types) */
|
|
367
115
|
max?: string;
|
|
368
|
-
|
|
369
|
-
* Pre-computed HTML input props for direct spreading.
|
|
370
|
-
* @example
|
|
371
|
-
* ```tsx
|
|
372
|
-
* <input {...field.inputProps} value={value} onChange={handleChange} />
|
|
373
|
-
* ```
|
|
374
|
-
*/
|
|
116
|
+
format: NumberFormat;
|
|
375
117
|
inputProps: PrimitiveInputProps;
|
|
118
|
+
defaultValue: string;
|
|
376
119
|
}
|
|
377
|
-
|
|
378
|
-
type: "text";
|
|
379
|
-
/** Minimum length constraint */
|
|
120
|
+
interface TextExtras {
|
|
380
121
|
minLength?: number;
|
|
381
|
-
/** Maximum length constraint */
|
|
382
122
|
maxLength?: number;
|
|
383
|
-
/** Whether to render as multiline textarea */
|
|
384
123
|
multiline?: boolean;
|
|
385
|
-
|
|
386
|
-
* Pre-computed HTML input props for direct spreading.
|
|
387
|
-
* @example
|
|
388
|
-
* ```tsx
|
|
389
|
-
* <input {...field.inputProps} value={value} onChange={handleChange} />
|
|
390
|
-
* ```
|
|
391
|
-
*/
|
|
124
|
+
format: TextFormat;
|
|
392
125
|
inputProps: PrimitiveInputProps;
|
|
126
|
+
defaultValue: string;
|
|
393
127
|
}
|
|
394
|
-
|
|
395
|
-
type: "boolean";
|
|
396
|
-
/**
|
|
397
|
-
* Pre-computed HTML input props for direct spreading.
|
|
398
|
-
* @example
|
|
399
|
-
* ```tsx
|
|
400
|
-
* <input {...field.inputProps} checked={value} onChange={handleChange} />
|
|
401
|
-
* ```
|
|
402
|
-
*/
|
|
128
|
+
interface BooleanExtras {
|
|
403
129
|
inputProps: PrimitiveInputProps;
|
|
130
|
+
defaultValue: boolean;
|
|
404
131
|
}
|
|
405
|
-
|
|
406
|
-
|
|
132
|
+
interface NullExtras {
|
|
133
|
+
defaultValue: null;
|
|
407
134
|
}
|
|
408
|
-
|
|
409
|
-
|
|
135
|
+
interface UnknownExtras {
|
|
136
|
+
defaultValue: undefined;
|
|
410
137
|
}
|
|
411
|
-
|
|
138
|
+
type FieldExtras<T extends VisitorDataType> = T extends "record" ? RecordExtras : T extends "variant" ? VariantExtras : T extends "tuple" ? TupleExtras : T extends "optional" ? OptionalExtras : T extends "vector" ? VectorExtras : T extends "blob" ? BlobExtras : T extends "recursive" ? RecursiveExtras : T extends "principal" ? PrincipalExtras : T extends "number" ? NumberExtras : T extends "text" ? TextExtras : T extends "boolean" ? BooleanExtras : T extends "null" ? NullExtras : T extends "unknown" ? UnknownExtras : {};
|
|
412
139
|
/**
|
|
413
|
-
*
|
|
414
|
-
* Contains all information needed to create a TanStack Form instance.
|
|
415
|
-
*
|
|
416
|
-
* @example
|
|
417
|
-
* ```tsx
|
|
418
|
-
* import { useForm } from '@tanstack/react-form'
|
|
419
|
-
*
|
|
420
|
-
* function MethodForm({ meta }: { meta: FormMeta }) {
|
|
421
|
-
* const form = useForm({
|
|
422
|
-
* ...meta.formOptions,
|
|
423
|
-
* onSubmit: async ({ value }) => {
|
|
424
|
-
* await actor[meta.functionName](...value)
|
|
425
|
-
* }
|
|
426
|
-
* })
|
|
427
|
-
*
|
|
428
|
-
* return (
|
|
429
|
-
* <form onSubmit={(e) => { e.preventDefault(); form.handleSubmit() }}>
|
|
430
|
-
* {meta.fields.map(field => (
|
|
431
|
-
* <form.Field key={field.name} name={field.name}>
|
|
432
|
-
* {(fieldApi) => <DynamicInput field={field} fieldApi={fieldApi} />}
|
|
433
|
-
* </form.Field>
|
|
434
|
-
* ))}
|
|
435
|
-
* <button type="submit">Submit</button>
|
|
436
|
-
* </form>
|
|
437
|
-
* )
|
|
438
|
-
* }
|
|
439
|
-
* ```
|
|
140
|
+
* A unified field node that contains all metadata needed for rendering.
|
|
440
141
|
*/
|
|
142
|
+
export type FieldNode<T extends VisitorDataType = VisitorDataType> = T extends any ? FieldBase<T> & FieldExtras<T> : never;
|
|
143
|
+
export type RecordField = FieldNode<"record">;
|
|
144
|
+
export type VariantField = FieldNode<"variant">;
|
|
145
|
+
export type TupleField = FieldNode<"tuple">;
|
|
146
|
+
export type OptionalField = FieldNode<"optional">;
|
|
147
|
+
export type VectorField = FieldNode<"vector">;
|
|
148
|
+
export type BlobField = FieldNode<"blob">;
|
|
149
|
+
export type RecursiveField = FieldNode<"recursive">;
|
|
150
|
+
export type PrincipalField = FieldNode<"principal">;
|
|
151
|
+
export type NumberField = FieldNode<"number">;
|
|
152
|
+
export type TextField = FieldNode<"text">;
|
|
153
|
+
export type BooleanField = FieldNode<"boolean">;
|
|
154
|
+
export type NullField = FieldNode<"null">;
|
|
155
|
+
export type UnknownField = FieldNode<"unknown">;
|
|
441
156
|
export interface ArgumentsMeta<A = BaseActor, Name extends FunctionName<A> = FunctionName<A>> {
|
|
442
|
-
/** Whether this is a "query" or "update" function */
|
|
443
157
|
functionType: FunctionType;
|
|
444
|
-
/** The function name */
|
|
445
158
|
functionName: Name;
|
|
446
|
-
|
|
447
|
-
fields: Field[];
|
|
448
|
-
/** Default values for all arguments (as a tuple) */
|
|
159
|
+
fields: FieldNode[];
|
|
449
160
|
defaultValues: unknown[];
|
|
450
|
-
/** Combined Zod schema for all arguments */
|
|
451
161
|
schema: z.ZodTuple<[z.ZodTypeAny, ...z.ZodTypeAny[]]>;
|
|
452
|
-
/** Number of arguments */
|
|
453
162
|
argCount: number;
|
|
454
|
-
/** Whether the function takes no arguments */
|
|
455
163
|
isNoArgs: boolean;
|
|
456
164
|
}
|
|
457
|
-
/**
|
|
458
|
-
* Options that can be spread into useForm().
|
|
459
|
-
* Pre-configured with defaultValues and validators.
|
|
460
|
-
*/
|
|
461
165
|
export interface FormOptions {
|
|
462
|
-
/** Initial form values */
|
|
463
166
|
defaultValues: unknown[];
|
|
464
|
-
/** Validators using the Zod schema */
|
|
465
167
|
validators: {
|
|
466
168
|
onChange: z.ZodTypeAny;
|
|
467
169
|
onBlur: z.ZodTypeAny;
|
|
468
170
|
};
|
|
469
171
|
}
|
|
470
|
-
/**
|
|
471
|
-
* Service-level form metadata.
|
|
472
|
-
* Maps each method name to its FormMeta.
|
|
473
|
-
*/
|
|
474
172
|
export type ArgumentsServiceMeta<A = BaseActor> = {
|
|
475
173
|
[K in FunctionName<A>]: ArgumentsMeta<A, K>;
|
|
476
174
|
};
|
|
477
|
-
|
|
478
|
-
export type FieldByType<T extends ArgumentFieldType> = Extract<Field, {
|
|
175
|
+
export type FieldByType<T extends VisitorDataType> = Extract<FieldNode, {
|
|
479
176
|
type: T;
|
|
480
177
|
}>;
|
|
481
|
-
|
|
482
|
-
* Props type helper for field components.
|
|
483
|
-
* Use this to type your field components for better DX.
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* ```tsx
|
|
487
|
-
* const VariantField: React.FC<FieldProps<'variant'>> = ({ field, renderField }) => {
|
|
488
|
-
* // field is properly typed as VariantField
|
|
489
|
-
* return (
|
|
490
|
-
* <div>
|
|
491
|
-
* <select>{field.options.map(opt => ...)}</select>
|
|
492
|
-
* {renderField?.(field.getSelectedField(currentValue))}
|
|
493
|
-
* </div>
|
|
494
|
-
* )
|
|
495
|
-
* }
|
|
496
|
-
* ```
|
|
497
|
-
*/
|
|
498
|
-
export type FieldProps<T extends ArgumentFieldType> = {
|
|
178
|
+
export type FieldProps<T extends VisitorDataType> = {
|
|
499
179
|
field: FieldByType<T>;
|
|
500
|
-
renderField?: (child:
|
|
180
|
+
renderField?: (child: FieldNode) => React.ReactNode;
|
|
501
181
|
};
|
|
502
|
-
/** Compound field types that contain other fields */
|
|
503
182
|
export type CompoundField = RecordField | VariantField | TupleField | OptionalField | VectorField | RecursiveField;
|
|
504
|
-
/** Primitive field types */
|
|
505
183
|
export type PrimitiveField = PrincipalField | NumberField | TextField | BooleanField | NullField;
|
|
506
|
-
/**
|
|
507
|
-
* A complete mapping of component types to React components.
|
|
508
|
-
* Use this type when defining your component map.
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```tsx
|
|
512
|
-
* const componentMap: ComponentMap<typeof MyTextInput, typeof MyNumberInput, ...> = {
|
|
513
|
-
* 'text-input': MyTextInput,
|
|
514
|
-
* 'number-input': MyNumberInput,
|
|
515
|
-
* // ...
|
|
516
|
-
* }
|
|
517
|
-
* ```
|
|
518
|
-
*/
|
|
519
|
-
export type ComponentMap<TComponents extends Record<FieldComponentType, unknown>> = {
|
|
520
|
-
[K in FieldComponentType]: TComponents[K];
|
|
521
|
-
};
|
|
522
|
-
/**
|
|
523
|
-
* Get the component type for a given field component type.
|
|
524
|
-
* Useful for typing dynamic component lookups.
|
|
525
|
-
*/
|
|
526
|
-
export type GetComponentType<TMap extends Partial<Record<FieldComponentType, unknown>>, TKey extends FieldComponentType> = TKey extends keyof TMap ? TMap[TKey] : never;
|
|
527
184
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/visitor/arguments/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC7E,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/visitor/arguments/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC7E,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAEzE,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,CAAA;AAMzD;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,aAAa,GACb,iBAAiB,GACjB,YAAY,GACZ,cAAc,GACd,kBAAkB,GAClB,aAAa,GACb,gBAAgB,GAChB,kBAAkB,CAAA;AAEtB;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,QAAQ,GACR,UAAU,GACV,QAAQ,GACR,MAAM,GACN,UAAU,CAAA;AAEd;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE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AAE,CACZ,CAAA;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,eAAe,IAAI;IAClD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IACrB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,KAAK,CAAC,SAAS,CAAA;CACpD,CAAA;AAED,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,YAAY,GACZ,UAAU,GACV,aAAa,GACb,WAAW,GACX,cAAc,CAAA;AAElB,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,WAAW,GACX,SAAS,GACT,YAAY,GACZ,SAAS,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/visitor/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/visitor/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AA4C/D,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,KAAG,UAmBhD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,KAAG,YAKlD,CAAA"}
|