@ic-reactor/candid 3.0.18-beta.0 → 3.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.
Files changed (63) hide show
  1. package/README.md +41 -14
  2. package/dist/display-reactor.d.ts.map +1 -1
  3. package/dist/display-reactor.js +1 -1
  4. package/dist/display-reactor.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/metadata-display-reactor.d.ts +4 -4
  10. package/dist/metadata-display-reactor.d.ts.map +1 -1
  11. package/dist/metadata-display-reactor.js +1 -1
  12. package/dist/metadata-display-reactor.js.map +1 -1
  13. package/dist/metadata-reactor.d.ts +51 -0
  14. package/dist/metadata-reactor.d.ts.map +1 -0
  15. package/dist/metadata-reactor.js +202 -0
  16. package/dist/metadata-reactor.js.map +1 -0
  17. package/dist/reactor.d.ts +3 -2
  18. package/dist/reactor.d.ts.map +1 -1
  19. package/dist/reactor.js +6 -0
  20. package/dist/reactor.js.map +1 -1
  21. package/dist/types.d.ts +10 -0
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/visitor/arguments/helpers.d.ts.map +1 -1
  24. package/dist/visitor/arguments/helpers.js +10 -2
  25. package/dist/visitor/arguments/helpers.js.map +1 -1
  26. package/dist/visitor/candid/helpers.d.ts +4 -0
  27. package/dist/visitor/candid/helpers.d.ts.map +1 -0
  28. package/dist/visitor/candid/helpers.js +84 -0
  29. package/dist/visitor/candid/helpers.js.map +1 -0
  30. package/dist/visitor/candid/index.d.ts +46 -0
  31. package/dist/visitor/candid/index.d.ts.map +1 -0
  32. package/dist/visitor/candid/index.js +421 -0
  33. package/dist/visitor/candid/index.js.map +1 -0
  34. package/dist/visitor/candid/types.d.ts +168 -0
  35. package/dist/visitor/candid/types.d.ts.map +1 -0
  36. package/dist/visitor/candid/types.js +2 -0
  37. package/dist/visitor/candid/types.js.map +1 -0
  38. package/dist/visitor/constants.d.ts +1 -1
  39. package/dist/visitor/constants.d.ts.map +1 -1
  40. package/dist/visitor/index.d.ts +1 -0
  41. package/dist/visitor/index.d.ts.map +1 -1
  42. package/dist/visitor/index.js +1 -0
  43. package/dist/visitor/index.js.map +1 -1
  44. package/dist/visitor/returns/index.d.ts.map +1 -1
  45. package/dist/visitor/returns/index.js +1 -1
  46. package/dist/visitor/returns/index.js.map +1 -1
  47. package/dist/visitor/returns/types.d.ts +1 -1
  48. package/dist/visitor/returns/types.d.ts.map +1 -1
  49. package/package.json +11 -7
  50. package/src/display-reactor.ts +1 -2
  51. package/src/index.ts +1 -0
  52. package/src/metadata-display-reactor.ts +4 -4
  53. package/src/metadata-reactor.ts +304 -0
  54. package/src/reactor.ts +12 -2
  55. package/src/types.ts +11 -0
  56. package/src/visitor/arguments/helpers.ts +9 -2
  57. package/src/visitor/candid/helpers.ts +89 -0
  58. package/src/visitor/candid/index.ts +673 -0
  59. package/src/visitor/candid/types.ts +292 -0
  60. package/src/visitor/constants.ts +1 -1
  61. package/src/visitor/index.ts +1 -0
  62. package/src/visitor/returns/index.ts +6 -4
  63. package/src/visitor/returns/types.ts +0 -2
@@ -0,0 +1,292 @@
1
+ import type { BaseActor, FunctionName, FunctionType } from "@ic-reactor/core"
2
+ import * as z from "zod"
3
+
4
+ // ════════════════════════════════════════════════════════════════════════════
5
+ // Component & UI Types
6
+ // ════════════════════════════════════════════════════════════════════════════
7
+
8
+ /**
9
+ * Suggested component type for rendering friendly form fields.
10
+ */
11
+ export type FormFieldComponentType =
12
+ | "record-container"
13
+ | "tuple-container"
14
+ | "variant-select"
15
+ | "optional-toggle"
16
+ | "vector-list"
17
+ | "blob-upload"
18
+ | "principal-input"
19
+ | "text-input"
20
+ | "number-input"
21
+ | "boolean-checkbox"
22
+ | "null-hidden"
23
+ | "recursive-lazy"
24
+ | "unknown-fallback"
25
+
26
+ /**
27
+ * Input type hints for HTML input elements.
28
+ */
29
+ export type FormInputType =
30
+ | "text"
31
+ | "number"
32
+ | "checkbox"
33
+ | "select"
34
+ | "file"
35
+ | "textarea"
36
+
37
+ /**
38
+ * Rendering hints for the UI.
39
+ */
40
+ export interface FormRenderHint {
41
+ isCompound: boolean
42
+ isPrimitive: boolean
43
+ inputType?: FormInputType
44
+ }
45
+
46
+ // ════════════════════════════════════════════════════════════════════════════
47
+ // Field Types
48
+ // ════════════════════════════════════════════════════════════════════════════
49
+
50
+ export type FormFieldType =
51
+ | "record"
52
+ | "tuple"
53
+ | "variant"
54
+ | "optional"
55
+ | "vector"
56
+ | "blob"
57
+ | "principal"
58
+ | "text"
59
+ | "number"
60
+ | "boolean"
61
+ | "null"
62
+ | "recursive"
63
+ | "unknown"
64
+
65
+ // ════════════════════════════════════════════════════════════════════════════
66
+ // Base Field Interface
67
+ // ════════════════════════════════════════════════════════════════════════════
68
+
69
+ /**
70
+ * Base properties shared by all friendly form field nodes.
71
+ */
72
+ interface FormFieldBase<T extends FormFieldType = FormFieldType> {
73
+ type: T
74
+ label: string
75
+ displayLabel: string
76
+ name: string
77
+ component: FormFieldComponentType
78
+ renderHint: FormRenderHint
79
+ schema: z.ZodTypeAny
80
+ candidType: string
81
+ defaultValue: unknown
82
+ }
83
+
84
+ // ════════════════════════════════════════════════════════════════════════════
85
+ // Field Extras - Type-Specific Properties
86
+ // ════════════════════════════════════════════════════════════════════════════
87
+
88
+ interface FormRecordExtras {
89
+ fields: FormFieldNode[]
90
+ defaultValue: Record<string, unknown>
91
+ }
92
+
93
+ interface FormTupleExtras {
94
+ fields: FormFieldNode[]
95
+ defaultValue: unknown[]
96
+ }
97
+
98
+ interface FormVariantExtras {
99
+ options: FormFieldNode[]
100
+ defaultOption: string
101
+ defaultValue: Record<string, unknown>
102
+ getOptionDefault: (option: string) => Record<string, unknown>
103
+ getOption: (option: string) => FormFieldNode
104
+ getSelectedKey: (value: Record<string, unknown>) => string
105
+ getSelectedOption: (value: Record<string, unknown>) => FormFieldNode
106
+ }
107
+
108
+ interface FormOptionalExtras {
109
+ innerField: FormFieldNode
110
+ defaultValue: null
111
+ getInnerDefault: () => unknown
112
+ isEnabled: (value: unknown) => boolean
113
+ }
114
+
115
+ interface FormVectorExtras {
116
+ itemField: FormFieldNode
117
+ defaultValue: unknown[]
118
+ getItemDefault: () => unknown
119
+ createItemField: (
120
+ index: number,
121
+ overrides?: { label?: string }
122
+ ) => FormFieldNode
123
+ }
124
+
125
+ interface FormBlobExtras {
126
+ defaultValue: string
127
+ }
128
+
129
+ interface FormRecursiveExtras {
130
+ typeName: string
131
+ extract: () => FormFieldNode
132
+ defaultValue: undefined
133
+ }
134
+
135
+ interface FormPrincipalExtras {
136
+ defaultValue: string
137
+ }
138
+
139
+ interface FormTextExtras {
140
+ defaultValue: string
141
+ }
142
+
143
+ interface FormNumberExtras {
144
+ defaultValue: string
145
+ }
146
+
147
+ interface FormBooleanExtras {
148
+ defaultValue: boolean
149
+ }
150
+
151
+ interface FormNullExtras {
152
+ defaultValue: null
153
+ }
154
+
155
+ interface FormUnknownExtras {
156
+ defaultValue: null
157
+ }
158
+
159
+ type FormFieldExtras<T extends FormFieldType> = T extends "record"
160
+ ? FormRecordExtras
161
+ : T extends "tuple"
162
+ ? FormTupleExtras
163
+ : T extends "variant"
164
+ ? FormVariantExtras
165
+ : T extends "optional"
166
+ ? FormOptionalExtras
167
+ : T extends "vector"
168
+ ? FormVectorExtras
169
+ : T extends "blob"
170
+ ? FormBlobExtras
171
+ : T extends "recursive"
172
+ ? FormRecursiveExtras
173
+ : T extends "principal"
174
+ ? FormPrincipalExtras
175
+ : T extends "text"
176
+ ? FormTextExtras
177
+ : T extends "number"
178
+ ? FormNumberExtras
179
+ : T extends "boolean"
180
+ ? FormBooleanExtras
181
+ : T extends "null"
182
+ ? FormNullExtras
183
+ : T extends "unknown"
184
+ ? FormUnknownExtras
185
+ : {}
186
+
187
+ /**
188
+ * A unified friendly field node that contains all metadata needed for rendering.
189
+ */
190
+ export type FormFieldNode<T extends FormFieldType = FormFieldType> =
191
+ T extends any ? FormFieldBase<T> & FormFieldExtras<T> : never
192
+
193
+ export type FormRecordField = FormFieldNode<"record">
194
+ export type FormTupleField = FormFieldNode<"tuple">
195
+ export type FormVariantField = FormFieldNode<"variant">
196
+ export type FormOptionalField = FormFieldNode<"optional">
197
+ export type FormVectorField = FormFieldNode<"vector">
198
+ export type FormBlobField = FormFieldNode<"blob">
199
+ export type FormRecursiveField = FormFieldNode<"recursive">
200
+ export type FormPrincipalField = FormFieldNode<"principal">
201
+ export type FormTextField = FormFieldNode<"text">
202
+ export type FormNumberField = FormFieldNode<"number">
203
+ export type FormBooleanField = FormFieldNode<"boolean">
204
+ export type FormNullField = FormFieldNode<"null">
205
+ export type FormUnknownField = FormFieldNode<"unknown">
206
+
207
+ // ════════════════════════════════════════════════════════════════════════════
208
+ // Form Metadata
209
+ // ════════════════════════════════════════════════════════════════════════════
210
+
211
+ export type FriendlyFunctionType = FunctionType | "value"
212
+
213
+ /**
214
+ * Metadata for a method/value's friendly input arguments.
215
+ */
216
+ export interface FormArgumentsMeta {
217
+ candidType: string
218
+ functionType: FriendlyFunctionType
219
+ functionName: string
220
+ args: FormFieldNode[]
221
+ defaults: unknown[]
222
+ schema: z.ZodTypeAny
223
+ argCount: number
224
+ isEmpty: boolean
225
+ }
226
+
227
+ /**
228
+ * Service-level metadata mapping method names to their friendly argument metadata.
229
+ */
230
+ export type FormServiceMeta<A = BaseActor> = {
231
+ [K in FunctionName<A>]?: FormArgumentsMeta
232
+ }
233
+
234
+ // ════════════════════════════════════════════════════════════════════════════
235
+ // Type Utilities
236
+ // ════════════════════════════════════════════════════════════════════════════
237
+
238
+ /**
239
+ * Extract field type by FormFieldType.
240
+ */
241
+ export type FormFieldByType<T extends FormFieldType> = Extract<
242
+ FormFieldNode,
243
+ { type: T }
244
+ >
245
+
246
+ /** Compound field types that contain other fields */
247
+ export type FormCompoundField =
248
+ | FormRecordField
249
+ | FormTupleField
250
+ | FormVariantField
251
+ | FormOptionalField
252
+ | FormVectorField
253
+ | FormRecursiveField
254
+
255
+ /** Primitive field types with direct values */
256
+ export type FormPrimitiveField =
257
+ | FormBlobField
258
+ | FormPrincipalField
259
+ | FormTextField
260
+ | FormNumberField
261
+ | FormBooleanField
262
+ | FormNullField
263
+ | FormUnknownField
264
+
265
+ // ════════════════════════════════════════════════════════════════════════════
266
+ // Variable References
267
+ // ════════════════════════════════════════════════════════════════════════════
268
+
269
+ export interface VariableRefCandidate {
270
+ expr: string
271
+ label: string
272
+ candidType: string
273
+ fieldType: FormFieldType
274
+ sourceNodeId: string
275
+ sourceRoot?: "arg" | "ret"
276
+ }
277
+
278
+ export type ExprHydration =
279
+ | { status: "empty" }
280
+ | { status: "hydrated"; values: unknown[] }
281
+ | { status: "skipped"; reason: string }
282
+ | { status: "error"; message: string }
283
+
284
+ export type MethodMetadataOptions = {
285
+ candidArgsHex?: string
286
+ skipHydrationIfContains?: string
287
+ }
288
+
289
+ export type CandidFormMetadata = {
290
+ meta: FormArgumentsMeta
291
+ hydration: ExprHydration
292
+ }
@@ -1,4 +1,4 @@
1
- import type { TextFormat, NumberFormat } from "./returns/types"
1
+ import { NumberFormat, TextFormat } from "./types"
2
2
 
3
3
  const TAMESTAMP_KEYS = [
4
4
  "time",
@@ -2,3 +2,4 @@ export * from "./returns"
2
2
  export * from "./arguments"
3
3
  export * from "./types"
4
4
  export * from "./helpers"
5
+ export * from "./candid"
@@ -1,16 +1,18 @@
1
1
  import { isQuery } from "../helpers"
2
2
  import { checkTextFormat, checkNumberFormat } from "../constants"
3
3
  import { formatLabel } from "../arguments/helpers"
4
- import { MetadataError } from "../arguments/types"
4
+ import {
5
+ MetadataError,
6
+ NumberFormat,
7
+ TextFormat,
8
+ VisitorDataType,
9
+ } from "../arguments/types"
5
10
  import type {
6
11
  ResultNode,
7
12
  ResolvedNode,
8
- VisitorDataType,
9
13
  MethodMeta,
10
14
  ServiceMeta,
11
15
  MethodResult,
12
- NumberFormat,
13
- TextFormat,
14
16
  } from "./types"
15
17
 
16
18
  import { sha256 } from "@noble/hashes/sha2.js"
@@ -7,8 +7,6 @@ import type {
7
7
  import type { IDL } from "@icp-sdk/core/candid"
8
8
  import type { VisitorDataType, TextFormat, NumberFormat } from "../types"
9
9
 
10
- export type { VisitorDataType, TextFormat, NumberFormat }
11
-
12
10
  // ════════════════════════════════════════════════════════════════════════════
13
11
  // Core Types & Formats
14
12
  // ════════════════════════════════════════════════════════════════════════════