@ic-reactor/codegen 0.1.3 → 0.3.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/dist/index.d.cts CHANGED
@@ -1,72 +1,3 @@
1
- /**
2
- * Shared types for IC Reactor code generation
3
- */
4
- /**
5
- * Information about a canister method extracted from a .did file
6
- */
7
- interface MethodInfo {
8
- /** Method name as defined in the Candid interface */
9
- name: string;
10
- /** Whether this method is a query or update (mutation) */
11
- type: "query" | "mutation";
12
- /** Whether the method accepts arguments */
13
- hasArgs: boolean;
14
- /** Human-readable description of the arguments */
15
- argsDescription?: string;
16
- /** Human-readable description of the return type */
17
- returnDescription?: string;
18
- }
19
- /**
20
- * Configuration for a single canister
21
- */
22
- interface CanisterConfig {
23
- /** Name of the canister (used for variable naming) */
24
- name?: string;
25
- /** Path to the .did file */
26
- didFile: string;
27
- /** Output directory (default: ./src/canisters/<name>) */
28
- outDir?: string;
29
- /** Use DisplayReactor for automatic type transformations (default: true) */
30
- useDisplayReactor?: boolean;
31
- /**
32
- * Path to import ClientManager from (relative to generated file).
33
- * The file at this path should export: { clientManager: ClientManager }
34
- * Default: "../../lib/client"
35
- */
36
- clientManagerPath?: string;
37
- /** Custom canister ID (optional, uses environment by default) */
38
- canisterId?: string;
39
- }
40
- /**
41
- * Hook generation type
42
- */
43
- type HookType = "query" | "suspenseQuery" | "infiniteQuery" | "suspenseInfiniteQuery" | "mutation";
44
- /**
45
- * Options for generating a hook file
46
- */
47
- interface GeneratorOptions {
48
- canisterName: string;
49
- methodName: string;
50
- methodType: "query" | "mutation";
51
- hasArgs: boolean;
52
- outDir: string;
53
- }
54
- /**
55
- * Options for reactor file generation
56
- */
57
- interface ReactorGeneratorOptions {
58
- canisterName: string;
59
- canisterConfig: CanisterConfig;
60
- /** Global default clientManagerPath */
61
- globalClientManagerPath?: string;
62
- /** Whether declarations have been generated */
63
- hasDeclarations?: boolean;
64
- /** Whether to generate advanced per-method hooks (default: false) */
65
- advanced?: boolean;
66
- /** DID content (required when advanced=true) */
67
- didContent?: string;
68
- }
69
-
70
1
  /**
71
2
  * Naming utilities for code generation
72
3
  *
@@ -79,27 +10,6 @@ interface ReactorGeneratorOptions {
79
10
  * @example toPascalCase("my-canister") → "MyCanister"
80
11
  */
81
12
  declare function toPascalCase(str: string): string;
82
- /**
83
- * Convert string to camelCase
84
- * @example toCamelCase("get_message") → "getMessage"
85
- * @example toCamelCase("my-canister") → "myCanister"
86
- */
87
- declare function toCamelCase(str: string): string;
88
- /**
89
- * Generate hook file name
90
- * @example getHookFileName("get_message", "query") → "getMessageQuery.ts"
91
- */
92
- declare function getHookFileName(methodName: string, hookType: string): string;
93
- /**
94
- * Generate hook export name
95
- * @example getHookExportName("get_message", "query") → "getMessageQuery"
96
- */
97
- declare function getHookExportName(methodName: string, hookType: string): string;
98
- /**
99
- * Generate React hook name (with use prefix)
100
- * @example getReactHookName("get_message", "query") → "useGetMessageQuery"
101
- */
102
- declare function getReactHookName(methodName: string, hookType: string): string;
103
13
  /**
104
14
  * Generate reactor variable name
105
15
  * @example getReactorName("backend") → "backendReactor"
@@ -111,40 +21,10 @@ declare function getReactorName(canisterName: string): string;
111
21
  */
112
22
  declare function getServiceTypeName(canisterName: string): string;
113
23
 
114
- /**
115
- * DID file parser
116
- *
117
- * Extracts method information from Candid interface definition files.
118
- * Based on the CLI's parser implementation (with comment stripping).
119
- */
120
-
121
- /**
122
- * Parse a .did file and extract method information
123
- */
124
- declare function parseDIDFile(didFilePath: string): MethodInfo[];
125
- /**
126
- * Extract methods from DID content
127
- *
128
- * Handles formats like:
129
- * - `name : (args) -> (result)`
130
- * - `name : (args) -> (result) query`
131
- * - `name : (args) -> (result) composite_query`
132
- * - `name : func (args) -> (result)`
133
- */
134
- declare function extractMethods(didContent: string): MethodInfo[];
135
- /**
136
- * Get methods by type
137
- */
138
- declare function getMethodsByType(methods: MethodInfo[], type: "query" | "mutation"): MethodInfo[];
139
- /**
140
- * Format method info for display
141
- */
142
- declare function formatMethodForDisplay(method: MethodInfo): string;
143
-
144
24
  /**
145
25
  * Bindgen utilities
146
26
  *
147
- * Generates TypeScript declarations from Candid files using @icp-sdk/bindgen.
27
+ * Generates TypeScript declarations from Candid files using @ic-reactor/parser.
148
28
  */
149
29
  interface BindgenOptions {
150
30
  /** Path to the .did file */
@@ -163,75 +43,41 @@ interface BindgenResult {
163
43
  * Generate TypeScript declarations from a Candid file
164
44
  *
165
45
  * This creates:
166
- * - declarations/<canisterName>.did.ts - IDL factory and types
46
+ * - declarations/<canisterName>.js - IDL factory
47
+ * - declarations/<canisterName>.d.ts - Types
167
48
  */
168
49
  declare function generateDeclarations(options: BindgenOptions): Promise<BindgenResult>;
169
50
  /**
170
51
  * Check if declarations already exist for a canister
171
52
  */
172
53
  declare function declarationsExist(outDir: string, canisterName: string): boolean;
173
- /**
174
- * Save a Candid source to a file (for use with fetch command)
175
- */
176
- declare function saveCandidFile(candidSource: string, outDir: string, canisterName: string): string;
177
54
 
178
55
  /**
179
56
  * Reactor file template generator
180
57
  *
181
- * Generates the reactor instance file for a canister.
182
- * Supports simple mode (generic hooks) and advanced mode (per-method typed hooks).
58
+ * Generates the reactor instance file for a canister using DisplayReactor.
59
+ * Standardizes the output to include typed hooks and clean imports.
183
60
  */
184
-
61
+ type ReactorGeneratorOptions = {
62
+ canisterName: string;
63
+ didFile: string;
64
+ clientManagerPath?: string;
65
+ };
185
66
  /**
186
67
  * Generate the reactor file content
187
68
  */
188
69
  declare function generateReactorFile(options: ReactorGeneratorOptions): string;
189
70
 
190
71
  /**
191
- * Query hook template generator
192
- *
193
- * Generates createQuery/createQueryFactory-based hooks for canister query methods.
194
- */
195
-
196
- interface QueryHookOptions {
197
- canisterName: string;
198
- method: MethodInfo;
199
- type?: HookType;
200
- }
201
- /**
202
- * Generate a query hook file content
203
- */
204
- declare function generateQueryHook(options: QueryHookOptions): string;
205
-
206
- /**
207
- * Mutation hook template generator
208
- *
209
- * Generates createMutation-based hooks for canister update methods.
210
- */
211
-
212
- interface MutationHookOptions {
213
- canisterName: string;
214
- method: MethodInfo;
215
- }
216
- /**
217
- * Generate a mutation hook file content
72
+ * Client Manager Generator
218
73
  */
219
- declare function generateMutationHook(options: MutationHookOptions): string;
220
-
221
- /**
222
- * Infinite Query hook template generator
223
- *
224
- * Generates createInfiniteQuery-based hooks for paginated canister methods.
225
- */
226
-
227
- interface InfiniteQueryHookOptions {
228
- canisterName: string;
229
- method: MethodInfo;
230
- type?: HookType;
74
+ interface ClientGeneratorOptions {
75
+ /** Optional path to an existing queryClient */
76
+ queryClientPath?: string;
231
77
  }
232
78
  /**
233
- * Generate an infinite query hook file content
79
+ * Generate a central client manager file
234
80
  */
235
- declare function generateInfiniteQueryHook(options: InfiniteQueryHookOptions): string;
81
+ declare function generateClientFile(options?: ClientGeneratorOptions): string;
236
82
 
237
- export { type BindgenOptions, type BindgenResult, type CanisterConfig, type GeneratorOptions, type HookType, type InfiniteQueryHookOptions, type MethodInfo, type MutationHookOptions, type QueryHookOptions, type ReactorGeneratorOptions, declarationsExist, extractMethods, formatMethodForDisplay, generateDeclarations, generateInfiniteQueryHook, generateMutationHook, generateQueryHook, generateReactorFile, getHookExportName, getHookFileName, getMethodsByType, getReactHookName, getReactorName, getServiceTypeName, parseDIDFile, saveCandidFile, toCamelCase, toPascalCase };
83
+ export { type BindgenOptions, type BindgenResult, type ClientGeneratorOptions, type ReactorGeneratorOptions, declarationsExist, generateClientFile, generateDeclarations, generateReactorFile, getReactorName, getServiceTypeName, toPascalCase };
package/dist/index.d.ts CHANGED
@@ -1,72 +1,3 @@
1
- /**
2
- * Shared types for IC Reactor code generation
3
- */
4
- /**
5
- * Information about a canister method extracted from a .did file
6
- */
7
- interface MethodInfo {
8
- /** Method name as defined in the Candid interface */
9
- name: string;
10
- /** Whether this method is a query or update (mutation) */
11
- type: "query" | "mutation";
12
- /** Whether the method accepts arguments */
13
- hasArgs: boolean;
14
- /** Human-readable description of the arguments */
15
- argsDescription?: string;
16
- /** Human-readable description of the return type */
17
- returnDescription?: string;
18
- }
19
- /**
20
- * Configuration for a single canister
21
- */
22
- interface CanisterConfig {
23
- /** Name of the canister (used for variable naming) */
24
- name?: string;
25
- /** Path to the .did file */
26
- didFile: string;
27
- /** Output directory (default: ./src/canisters/<name>) */
28
- outDir?: string;
29
- /** Use DisplayReactor for automatic type transformations (default: true) */
30
- useDisplayReactor?: boolean;
31
- /**
32
- * Path to import ClientManager from (relative to generated file).
33
- * The file at this path should export: { clientManager: ClientManager }
34
- * Default: "../../lib/client"
35
- */
36
- clientManagerPath?: string;
37
- /** Custom canister ID (optional, uses environment by default) */
38
- canisterId?: string;
39
- }
40
- /**
41
- * Hook generation type
42
- */
43
- type HookType = "query" | "suspenseQuery" | "infiniteQuery" | "suspenseInfiniteQuery" | "mutation";
44
- /**
45
- * Options for generating a hook file
46
- */
47
- interface GeneratorOptions {
48
- canisterName: string;
49
- methodName: string;
50
- methodType: "query" | "mutation";
51
- hasArgs: boolean;
52
- outDir: string;
53
- }
54
- /**
55
- * Options for reactor file generation
56
- */
57
- interface ReactorGeneratorOptions {
58
- canisterName: string;
59
- canisterConfig: CanisterConfig;
60
- /** Global default clientManagerPath */
61
- globalClientManagerPath?: string;
62
- /** Whether declarations have been generated */
63
- hasDeclarations?: boolean;
64
- /** Whether to generate advanced per-method hooks (default: false) */
65
- advanced?: boolean;
66
- /** DID content (required when advanced=true) */
67
- didContent?: string;
68
- }
69
-
70
1
  /**
71
2
  * Naming utilities for code generation
72
3
  *
@@ -79,27 +10,6 @@ interface ReactorGeneratorOptions {
79
10
  * @example toPascalCase("my-canister") → "MyCanister"
80
11
  */
81
12
  declare function toPascalCase(str: string): string;
82
- /**
83
- * Convert string to camelCase
84
- * @example toCamelCase("get_message") → "getMessage"
85
- * @example toCamelCase("my-canister") → "myCanister"
86
- */
87
- declare function toCamelCase(str: string): string;
88
- /**
89
- * Generate hook file name
90
- * @example getHookFileName("get_message", "query") → "getMessageQuery.ts"
91
- */
92
- declare function getHookFileName(methodName: string, hookType: string): string;
93
- /**
94
- * Generate hook export name
95
- * @example getHookExportName("get_message", "query") → "getMessageQuery"
96
- */
97
- declare function getHookExportName(methodName: string, hookType: string): string;
98
- /**
99
- * Generate React hook name (with use prefix)
100
- * @example getReactHookName("get_message", "query") → "useGetMessageQuery"
101
- */
102
- declare function getReactHookName(methodName: string, hookType: string): string;
103
13
  /**
104
14
  * Generate reactor variable name
105
15
  * @example getReactorName("backend") → "backendReactor"
@@ -111,40 +21,10 @@ declare function getReactorName(canisterName: string): string;
111
21
  */
112
22
  declare function getServiceTypeName(canisterName: string): string;
113
23
 
114
- /**
115
- * DID file parser
116
- *
117
- * Extracts method information from Candid interface definition files.
118
- * Based on the CLI's parser implementation (with comment stripping).
119
- */
120
-
121
- /**
122
- * Parse a .did file and extract method information
123
- */
124
- declare function parseDIDFile(didFilePath: string): MethodInfo[];
125
- /**
126
- * Extract methods from DID content
127
- *
128
- * Handles formats like:
129
- * - `name : (args) -> (result)`
130
- * - `name : (args) -> (result) query`
131
- * - `name : (args) -> (result) composite_query`
132
- * - `name : func (args) -> (result)`
133
- */
134
- declare function extractMethods(didContent: string): MethodInfo[];
135
- /**
136
- * Get methods by type
137
- */
138
- declare function getMethodsByType(methods: MethodInfo[], type: "query" | "mutation"): MethodInfo[];
139
- /**
140
- * Format method info for display
141
- */
142
- declare function formatMethodForDisplay(method: MethodInfo): string;
143
-
144
24
  /**
145
25
  * Bindgen utilities
146
26
  *
147
- * Generates TypeScript declarations from Candid files using @icp-sdk/bindgen.
27
+ * Generates TypeScript declarations from Candid files using @ic-reactor/parser.
148
28
  */
149
29
  interface BindgenOptions {
150
30
  /** Path to the .did file */
@@ -163,75 +43,41 @@ interface BindgenResult {
163
43
  * Generate TypeScript declarations from a Candid file
164
44
  *
165
45
  * This creates:
166
- * - declarations/<canisterName>.did.ts - IDL factory and types
46
+ * - declarations/<canisterName>.js - IDL factory
47
+ * - declarations/<canisterName>.d.ts - Types
167
48
  */
168
49
  declare function generateDeclarations(options: BindgenOptions): Promise<BindgenResult>;
169
50
  /**
170
51
  * Check if declarations already exist for a canister
171
52
  */
172
53
  declare function declarationsExist(outDir: string, canisterName: string): boolean;
173
- /**
174
- * Save a Candid source to a file (for use with fetch command)
175
- */
176
- declare function saveCandidFile(candidSource: string, outDir: string, canisterName: string): string;
177
54
 
178
55
  /**
179
56
  * Reactor file template generator
180
57
  *
181
- * Generates the reactor instance file for a canister.
182
- * Supports simple mode (generic hooks) and advanced mode (per-method typed hooks).
58
+ * Generates the reactor instance file for a canister using DisplayReactor.
59
+ * Standardizes the output to include typed hooks and clean imports.
183
60
  */
184
-
61
+ type ReactorGeneratorOptions = {
62
+ canisterName: string;
63
+ didFile: string;
64
+ clientManagerPath?: string;
65
+ };
185
66
  /**
186
67
  * Generate the reactor file content
187
68
  */
188
69
  declare function generateReactorFile(options: ReactorGeneratorOptions): string;
189
70
 
190
71
  /**
191
- * Query hook template generator
192
- *
193
- * Generates createQuery/createQueryFactory-based hooks for canister query methods.
194
- */
195
-
196
- interface QueryHookOptions {
197
- canisterName: string;
198
- method: MethodInfo;
199
- type?: HookType;
200
- }
201
- /**
202
- * Generate a query hook file content
203
- */
204
- declare function generateQueryHook(options: QueryHookOptions): string;
205
-
206
- /**
207
- * Mutation hook template generator
208
- *
209
- * Generates createMutation-based hooks for canister update methods.
210
- */
211
-
212
- interface MutationHookOptions {
213
- canisterName: string;
214
- method: MethodInfo;
215
- }
216
- /**
217
- * Generate a mutation hook file content
72
+ * Client Manager Generator
218
73
  */
219
- declare function generateMutationHook(options: MutationHookOptions): string;
220
-
221
- /**
222
- * Infinite Query hook template generator
223
- *
224
- * Generates createInfiniteQuery-based hooks for paginated canister methods.
225
- */
226
-
227
- interface InfiniteQueryHookOptions {
228
- canisterName: string;
229
- method: MethodInfo;
230
- type?: HookType;
74
+ interface ClientGeneratorOptions {
75
+ /** Optional path to an existing queryClient */
76
+ queryClientPath?: string;
231
77
  }
232
78
  /**
233
- * Generate an infinite query hook file content
79
+ * Generate a central client manager file
234
80
  */
235
- declare function generateInfiniteQueryHook(options: InfiniteQueryHookOptions): string;
81
+ declare function generateClientFile(options?: ClientGeneratorOptions): string;
236
82
 
237
- export { type BindgenOptions, type BindgenResult, type CanisterConfig, type GeneratorOptions, type HookType, type InfiniteQueryHookOptions, type MethodInfo, type MutationHookOptions, type QueryHookOptions, type ReactorGeneratorOptions, declarationsExist, extractMethods, formatMethodForDisplay, generateDeclarations, generateInfiniteQueryHook, generateMutationHook, generateQueryHook, generateReactorFile, getHookExportName, getHookFileName, getMethodsByType, getReactHookName, getReactorName, getServiceTypeName, parseDIDFile, saveCandidFile, toCamelCase, toPascalCase };
83
+ export { type BindgenOptions, type BindgenResult, type ClientGeneratorOptions, type ReactorGeneratorOptions, declarationsExist, generateClientFile, generateDeclarations, generateReactorFile, getReactorName, getServiceTypeName, toPascalCase };