@lsby/net-core 0.1.3 → 0.1.5

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.
@@ -136,8 +136,102 @@ async function main(tsconfigPath, apiFolderPath, outputPath) {
136
136
  if (!(0, import_node_fs.existsSync)(outDir)) {
137
137
  (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
138
138
  }
139
- import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
140
- `);
139
+ var code = [
140
+ `export type InterfaceType = [${result.join(",")}]`,
141
+ "",
142
+ `type \u5143\u7EC4\u8F6C\u8054\u5408<T> = T extends any[] ? T[number] : never`,
143
+ "",
144
+ `type \u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
145
+ ` ? []`,
146
+ ` : A extends [infer x, ...infer xs]`,
147
+ ` ? 'path' extends keyof x`,
148
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
149
+ ` : never`,
150
+ ` : never`,
151
+ `type Get\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
152
+ ` ? []`,
153
+ ` : A extends [infer x, ...infer xs]`,
154
+ ` ? 'method' extends keyof x`,
155
+ ` ? x['method'] extends 'get'`,
156
+ ` ? 'path' extends keyof x`,
157
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
158
+ ` : never`,
159
+ ` : never`,
160
+ ` : never`,
161
+ ` : never`,
162
+ `type Post\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
163
+ ` ? []`,
164
+ ` : A extends [infer x, ...infer xs]`,
165
+ ` ? 'method' extends keyof x`,
166
+ ` ? x['method'] extends 'post'`,
167
+ ` ? 'path' extends keyof x`,
168
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
169
+ ` : never`,
170
+ ` : never`,
171
+ ` : never`,
172
+ ` : never`,
173
+ ``,
174
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, A = InterfaceType> = A extends []`,
175
+ ` ? []`,
176
+ ` : A extends [infer x, ...infer xs]`,
177
+ ` ? 'path' extends keyof x`,
178
+ ` ? x['path'] extends Path`,
179
+ ` ? 'input' extends keyof x`,
180
+ ` ? x['input']`,
181
+ ` : never`,
182
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, xs>`,
183
+ ` : never`,
184
+ ` : never`,
185
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, A = InterfaceType> = A extends []`,
186
+ ` ? []`,
187
+ ` : A extends [infer x, ...infer xs]`,
188
+ ` ? 'path' extends keyof x`,
189
+ ` ? x['path'] extends Path`,
190
+ ` ? 'method' extends keyof x`,
191
+ ` ? x['method']`,
192
+ ` : never`,
193
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, xs>`,
194
+ ` : never`,
195
+ ` : never`,
196
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
197
+ ` ? []`,
198
+ ` : A extends [infer x, ...infer xs]`,
199
+ ` ? 'path' extends keyof x`,
200
+ ` ? x['path'] extends Path`,
201
+ ` ? 'successOutput' extends keyof x`,
202
+ ` ? x['successOutput']`,
203
+ ` : never`,
204
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, xs>`,
205
+ ` : never`,
206
+ ` : never`,
207
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
208
+ ` ? []`,
209
+ ` : A extends [infer x, ...infer xs]`,
210
+ ` ? 'path' extends keyof x`,
211
+ ` ? x['path'] extends Path`,
212
+ ` ? 'errorOutput' extends keyof x`,
213
+ ` ? x['errorOutput']`,
214
+ ` : never`,
215
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, xs>`,
216
+ ` : never`,
217
+ ` : never`,
218
+ ``,
219
+ `export type \u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
220
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
221
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
222
+ ` \u65B9\u6CD5: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<\u8DEF\u5F84>,`,
223
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
224
+ `export type Get\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Get\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
225
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
226
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
227
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
228
+ `export type Post\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Post\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
229
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
230
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
231
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
232
+ ""
233
+ ];
234
+ import_node_fs.default.writeFileSync(outputPathAbs, code.join("\n"));
141
235
  await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
142
236
  }
143
237
 
@@ -141,8 +141,102 @@ async function main(tsconfigPath, apiFolderPath, outputPath) {
141
141
  if (!(0, import_node_fs.existsSync)(outDir)) {
142
142
  (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
143
143
  }
144
- import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
145
- `);
144
+ var code = [
145
+ `export type InterfaceType = [${result.join(",")}]`,
146
+ "",
147
+ `type \u5143\u7EC4\u8F6C\u8054\u5408<T> = T extends any[] ? T[number] : never`,
148
+ "",
149
+ `type \u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
150
+ ` ? []`,
151
+ ` : A extends [infer x, ...infer xs]`,
152
+ ` ? 'path' extends keyof x`,
153
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
154
+ ` : never`,
155
+ ` : never`,
156
+ `type Get\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
157
+ ` ? []`,
158
+ ` : A extends [infer x, ...infer xs]`,
159
+ ` ? 'method' extends keyof x`,
160
+ ` ? x['method'] extends 'get'`,
161
+ ` ? 'path' extends keyof x`,
162
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
163
+ ` : never`,
164
+ ` : never`,
165
+ ` : never`,
166
+ ` : never`,
167
+ `type Post\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
168
+ ` ? []`,
169
+ ` : A extends [infer x, ...infer xs]`,
170
+ ` ? 'method' extends keyof x`,
171
+ ` ? x['method'] extends 'post'`,
172
+ ` ? 'path' extends keyof x`,
173
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
174
+ ` : never`,
175
+ ` : never`,
176
+ ` : never`,
177
+ ` : never`,
178
+ ``,
179
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, A = InterfaceType> = A extends []`,
180
+ ` ? []`,
181
+ ` : A extends [infer x, ...infer xs]`,
182
+ ` ? 'path' extends keyof x`,
183
+ ` ? x['path'] extends Path`,
184
+ ` ? 'input' extends keyof x`,
185
+ ` ? x['input']`,
186
+ ` : never`,
187
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, xs>`,
188
+ ` : never`,
189
+ ` : never`,
190
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, A = InterfaceType> = A extends []`,
191
+ ` ? []`,
192
+ ` : A extends [infer x, ...infer xs]`,
193
+ ` ? 'path' extends keyof x`,
194
+ ` ? x['path'] extends Path`,
195
+ ` ? 'method' extends keyof x`,
196
+ ` ? x['method']`,
197
+ ` : never`,
198
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, xs>`,
199
+ ` : never`,
200
+ ` : never`,
201
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
202
+ ` ? []`,
203
+ ` : A extends [infer x, ...infer xs]`,
204
+ ` ? 'path' extends keyof x`,
205
+ ` ? x['path'] extends Path`,
206
+ ` ? 'successOutput' extends keyof x`,
207
+ ` ? x['successOutput']`,
208
+ ` : never`,
209
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, xs>`,
210
+ ` : never`,
211
+ ` : never`,
212
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
213
+ ` ? []`,
214
+ ` : A extends [infer x, ...infer xs]`,
215
+ ` ? 'path' extends keyof x`,
216
+ ` ? x['path'] extends Path`,
217
+ ` ? 'errorOutput' extends keyof x`,
218
+ ` ? x['errorOutput']`,
219
+ ` : never`,
220
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, xs>`,
221
+ ` : never`,
222
+ ` : never`,
223
+ ``,
224
+ `export type \u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
225
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
226
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
227
+ ` \u65B9\u6CD5: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<\u8DEF\u5F84>,`,
228
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
229
+ `export type Get\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Get\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
230
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
231
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
232
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
233
+ `export type Post\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Post\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
234
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
235
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
236
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
237
+ ""
238
+ ];
239
+ import_node_fs.default.writeFileSync(outputPathAbs, code.join("\n"));
146
240
  await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
147
241
  }
148
242
  // Annotate the CommonJS export names for ESM import in node:
@@ -136,8 +136,102 @@ async function main(tsconfigPath, apiFolderPath, outputPath) {
136
136
  if (!(0, import_node_fs.existsSync)(outDir)) {
137
137
  (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
138
138
  }
139
- import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
140
- `);
139
+ var code = [
140
+ `export type InterfaceType = [${result.join(",")}]`,
141
+ "",
142
+ `type \u5143\u7EC4\u8F6C\u8054\u5408<T> = T extends any[] ? T[number] : never`,
143
+ "",
144
+ `type \u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
145
+ ` ? []`,
146
+ ` : A extends [infer x, ...infer xs]`,
147
+ ` ? 'path' extends keyof x`,
148
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
149
+ ` : never`,
150
+ ` : never`,
151
+ `type Get\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
152
+ ` ? []`,
153
+ ` : A extends [infer x, ...infer xs]`,
154
+ ` ? 'method' extends keyof x`,
155
+ ` ? x['method'] extends 'get'`,
156
+ ` ? 'path' extends keyof x`,
157
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
158
+ ` : never`,
159
+ ` : never`,
160
+ ` : never`,
161
+ ` : never`,
162
+ `type Post\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
163
+ ` ? []`,
164
+ ` : A extends [infer x, ...infer xs]`,
165
+ ` ? 'method' extends keyof x`,
166
+ ` ? x['method'] extends 'post'`,
167
+ ` ? 'path' extends keyof x`,
168
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
169
+ ` : never`,
170
+ ` : never`,
171
+ ` : never`,
172
+ ` : never`,
173
+ ``,
174
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, A = InterfaceType> = A extends []`,
175
+ ` ? []`,
176
+ ` : A extends [infer x, ...infer xs]`,
177
+ ` ? 'path' extends keyof x`,
178
+ ` ? x['path'] extends Path`,
179
+ ` ? 'input' extends keyof x`,
180
+ ` ? x['input']`,
181
+ ` : never`,
182
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, xs>`,
183
+ ` : never`,
184
+ ` : never`,
185
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, A = InterfaceType> = A extends []`,
186
+ ` ? []`,
187
+ ` : A extends [infer x, ...infer xs]`,
188
+ ` ? 'path' extends keyof x`,
189
+ ` ? x['path'] extends Path`,
190
+ ` ? 'method' extends keyof x`,
191
+ ` ? x['method']`,
192
+ ` : never`,
193
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, xs>`,
194
+ ` : never`,
195
+ ` : never`,
196
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
197
+ ` ? []`,
198
+ ` : A extends [infer x, ...infer xs]`,
199
+ ` ? 'path' extends keyof x`,
200
+ ` ? x['path'] extends Path`,
201
+ ` ? 'successOutput' extends keyof x`,
202
+ ` ? x['successOutput']`,
203
+ ` : never`,
204
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, xs>`,
205
+ ` : never`,
206
+ ` : never`,
207
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
208
+ ` ? []`,
209
+ ` : A extends [infer x, ...infer xs]`,
210
+ ` ? 'path' extends keyof x`,
211
+ ` ? x['path'] extends Path`,
212
+ ` ? 'errorOutput' extends keyof x`,
213
+ ` ? x['errorOutput']`,
214
+ ` : never`,
215
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, xs>`,
216
+ ` : never`,
217
+ ` : never`,
218
+ ``,
219
+ `export type \u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
220
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
221
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
222
+ ` \u65B9\u6CD5: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<\u8DEF\u5F84>,`,
223
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
224
+ `export type Get\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Get\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
225
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
226
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
227
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
228
+ `export type Post\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Post\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
229
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
230
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
231
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
232
+ ""
233
+ ];
234
+ import_node_fs.default.writeFileSync(outputPathAbs, code.join("\n"));
141
235
  await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
142
236
  }
143
237
 
@@ -141,8 +141,102 @@ async function main(tsconfigPath, apiFolderPath, outputPath) {
141
141
  if (!(0, import_node_fs.existsSync)(outDir)) {
142
142
  (0, import_node_fs.mkdirSync)(outDir, { recursive: true });
143
143
  }
144
- import_node_fs.default.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
145
- `);
144
+ var code = [
145
+ `export type InterfaceType = [${result.join(",")}]`,
146
+ "",
147
+ `type \u5143\u7EC4\u8F6C\u8054\u5408<T> = T extends any[] ? T[number] : never`,
148
+ "",
149
+ `type \u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
150
+ ` ? []`,
151
+ ` : A extends [infer x, ...infer xs]`,
152
+ ` ? 'path' extends keyof x`,
153
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
154
+ ` : never`,
155
+ ` : never`,
156
+ `type Get\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
157
+ ` ? []`,
158
+ ` : A extends [infer x, ...infer xs]`,
159
+ ` ? 'method' extends keyof x`,
160
+ ` ? x['method'] extends 'get'`,
161
+ ` ? 'path' extends keyof x`,
162
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
163
+ ` : never`,
164
+ ` : never`,
165
+ ` : never`,
166
+ ` : never`,
167
+ `type Post\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
168
+ ` ? []`,
169
+ ` : A extends [infer x, ...infer xs]`,
170
+ ` ? 'method' extends keyof x`,
171
+ ` ? x['method'] extends 'post'`,
172
+ ` ? 'path' extends keyof x`,
173
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
174
+ ` : never`,
175
+ ` : never`,
176
+ ` : never`,
177
+ ` : never`,
178
+ ``,
179
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, A = InterfaceType> = A extends []`,
180
+ ` ? []`,
181
+ ` : A extends [infer x, ...infer xs]`,
182
+ ` ? 'path' extends keyof x`,
183
+ ` ? x['path'] extends Path`,
184
+ ` ? 'input' extends keyof x`,
185
+ ` ? x['input']`,
186
+ ` : never`,
187
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, xs>`,
188
+ ` : never`,
189
+ ` : never`,
190
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, A = InterfaceType> = A extends []`,
191
+ ` ? []`,
192
+ ` : A extends [infer x, ...infer xs]`,
193
+ ` ? 'path' extends keyof x`,
194
+ ` ? x['path'] extends Path`,
195
+ ` ? 'method' extends keyof x`,
196
+ ` ? x['method']`,
197
+ ` : never`,
198
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, xs>`,
199
+ ` : never`,
200
+ ` : never`,
201
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
202
+ ` ? []`,
203
+ ` : A extends [infer x, ...infer xs]`,
204
+ ` ? 'path' extends keyof x`,
205
+ ` ? x['path'] extends Path`,
206
+ ` ? 'successOutput' extends keyof x`,
207
+ ` ? x['successOutput']`,
208
+ ` : never`,
209
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, xs>`,
210
+ ` : never`,
211
+ ` : never`,
212
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
213
+ ` ? []`,
214
+ ` : A extends [infer x, ...infer xs]`,
215
+ ` ? 'path' extends keyof x`,
216
+ ` ? x['path'] extends Path`,
217
+ ` ? 'errorOutput' extends keyof x`,
218
+ ` ? x['errorOutput']`,
219
+ ` : never`,
220
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, xs>`,
221
+ ` : never`,
222
+ ` : never`,
223
+ ``,
224
+ `export type \u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
225
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
226
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
227
+ ` \u65B9\u6CD5: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<\u8DEF\u5F84>,`,
228
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
229
+ `export type Get\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Get\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
230
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
231
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
232
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
233
+ `export type Post\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Post\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
234
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
235
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
236
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
237
+ ""
238
+ ];
239
+ import_node_fs.default.writeFileSync(outputPathAbs, code.join("\n"));
146
240
  await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
147
241
  }
148
242
  // Annotate the CommonJS export names for ESM import in node:
@@ -12,7 +12,7 @@ declare class JSON解析插件<Result extends z.ZodObject<{
12
12
  }
13
13
  type 任意JSON解析插件 = JSON解析插件<any>;
14
14
  type 任意JSON解析插件项 = _____<任意JSON解析插件>;
15
- type 合并JSON插件结果<Arr extends Array<_____$1>> = Arr extends [] ? {} : Arr extends [infer x, ...infer xs] ? x extends infer 插件项 ? xs extends Array<_____$1> ? 插件项 extends 任意JSON解析插件项 ? z.infer<_______<插件项>>['body'] & ______<xs> : {} : {} : {} : {};
15
+ type 合并JSON插件结果<Arr extends Array<_____$1>> = Arr extends [] ? {} : Arr extends [infer x, ...infer xs] ? x extends infer 插件项 ? xs extends Array<_____$1> ? 插件项 extends 任意JSON解析插件项 ? z.infer<_______<插件项>>['body'] & ______<xs> : 合并JSON插件结果<xs> : {} : {} : {};
16
16
  type 从接口类型获得JSON参数<接口类型描述> = 合并JSON插件结果<_______$1<接口类型描述>>;
17
17
 
18
18
  export { JSON解析插件, type 从接口类型获得JSON参数, type 任意JSON解析插件, type 任意JSON解析插件项, type 合并JSON插件结果 };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  main
4
- } from "../../chunk-JGLEEW7I.js";
4
+ } from "../../chunk-E3LVF7RJ.js";
5
5
  import "../../chunk-IRKJYOPK.js";
6
6
 
7
7
  // src/bin/gen-type/bin.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  main
3
- } from "../../chunk-JGLEEW7I.js";
3
+ } from "../../chunk-E3LVF7RJ.js";
4
4
  import "../../chunk-IRKJYOPK.js";
5
5
  export {
6
6
  main
@@ -0,0 +1,187 @@
1
+ import {
2
+ calcCode
3
+ } from "./chunk-IRKJYOPK.js";
4
+
5
+ // src/bin/gen-type/index.ts
6
+ import { randomUUID } from "node:crypto";
7
+ import fs, { existsSync, mkdirSync } from "node:fs";
8
+ import path from "node:path";
9
+ import ts from "typescript";
10
+ import { Log } from "@lsby/ts-log";
11
+ async function main(tsconfigPath, apiFolderPath, outputPath) {
12
+ var log = new Log("@lsby:net-core").extend("gen-type");
13
+ await log.debug("\u51C6\u5907\u751F\u6210\u7C7B\u578B\u6587\u4EF6...");
14
+ const tsconfigJson = ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, "utf8"));
15
+ if (tsconfigJson.error) {
16
+ throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
17
+ }
18
+ const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfigJson.config, ts.sys, path.resolve(tsconfigPath, ".."));
19
+ await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...");
20
+ const projectHost = ts.createCompilerHost(parsedTsconfig.options);
21
+ const project = ts.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
22
+ await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...");
23
+ const allSourceFiles = project.getSourceFiles();
24
+ const apiSourceFiles = allSourceFiles.filter((sourceFile) => {
25
+ return new RegExp(`${apiFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(path.resolve(sourceFile.fileName));
26
+ });
27
+ await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3...", apiSourceFiles.length);
28
+ const apiTypeCalcFileNames = apiSourceFiles.map(
29
+ (sourceFile) => sourceFile.fileName.replace("type.ts", `type-calculate-${randomUUID()}.ts`)
30
+ );
31
+ const apiTypeCalcFiles = apiTypeCalcFileNames.map((filename) => {
32
+ return {
33
+ name: filename,
34
+ sourceFile: ts.createSourceFile(filename, calcCode, ts.ScriptTarget.Latest)
35
+ };
36
+ });
37
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u8BA1\u7B97\u6587\u4EF6...");
38
+ const newProject = ts.createProgram({
39
+ rootNames: [...parsedTsconfig.fileNames, ...apiTypeCalcFileNames],
40
+ options: parsedTsconfig.options,
41
+ host: {
42
+ ...projectHost,
43
+ getSourceFile: (filename) => {
44
+ const apiTypeCalcSourceFile = apiTypeCalcFiles.find(
45
+ (apiTypeCalcSourceFile2) => apiTypeCalcSourceFile2.name === filename
46
+ );
47
+ if (apiTypeCalcSourceFile !== void 0) {
48
+ return apiTypeCalcSourceFile.sourceFile;
49
+ }
50
+ return project.getSourceFile(filename);
51
+ }
52
+ },
53
+ oldProgram: project
54
+ });
55
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE...");
56
+ const check = newProject.getTypeChecker();
57
+ await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE\u7C7B\u578B\u68C0\u67E5\u5668...");
58
+ const result = [];
59
+ for (var index = 0; index < apiSourceFiles.length; index++) {
60
+ var apiSourceFile = apiSourceFiles[index];
61
+ if (apiSourceFile == null)
62
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
63
+ await log.info(`\u5904\u7406\uFF08${index + 1} / ${apiSourceFiles.length}\uFF09\uFF1A${apiSourceFile.fileName}`);
64
+ const apiCalcSourceFile = apiTypeCalcFiles[index]?.sourceFile;
65
+ if (apiCalcSourceFile === void 0) {
66
+ throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
67
+ }
68
+ for (const node of apiCalcSourceFile.statements) {
69
+ if (ts.isExportAssignment(node) && node.isExportEquals === void 0) {
70
+ const apiType = check.getTypeAtLocation(node.expression);
71
+ const typeString = check.typeToString(
72
+ apiType,
73
+ void 0,
74
+ ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
75
+ );
76
+ result.push(typeString);
77
+ }
78
+ }
79
+ }
80
+ await log.debug("\u6210\u529F\u5904\u7406\u6240\u6709\u63A5\u53E3...");
81
+ const outputPathAbs = path.resolve(outputPath);
82
+ var outDir = path.dirname(outputPathAbs);
83
+ if (!existsSync(outDir)) {
84
+ mkdirSync(outDir, { recursive: true });
85
+ }
86
+ var code = [
87
+ `export type InterfaceType = [${result.join(",")}]`,
88
+ "",
89
+ `type \u5143\u7EC4\u8F6C\u8054\u5408<T> = T extends any[] ? T[number] : never`,
90
+ "",
91
+ `type \u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
92
+ ` ? []`,
93
+ ` : A extends [infer x, ...infer xs]`,
94
+ ` ? 'path' extends keyof x`,
95
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
96
+ ` : never`,
97
+ ` : never`,
98
+ `type Get\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
99
+ ` ? []`,
100
+ ` : A extends [infer x, ...infer xs]`,
101
+ ` ? 'method' extends keyof x`,
102
+ ` ? x['method'] extends 'get'`,
103
+ ` ? 'path' extends keyof x`,
104
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
105
+ ` : never`,
106
+ ` : never`,
107
+ ` : never`,
108
+ ` : never`,
109
+ `type Post\u63A5\u53E3\u8DEF\u5F84\u4EEC<A = InterfaceType> = A extends []`,
110
+ ` ? []`,
111
+ ` : A extends [infer x, ...infer xs]`,
112
+ ` ? 'method' extends keyof x`,
113
+ ` ? x['method'] extends 'post'`,
114
+ ` ? 'path' extends keyof x`,
115
+ ` ? [x['path'], ...\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC<xs>]`,
116
+ ` : never`,
117
+ ` : never`,
118
+ ` : never`,
119
+ ` : never`,
120
+ ``,
121
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, A = InterfaceType> = A extends []`,
122
+ ` ? []`,
123
+ ` : A extends [infer x, ...infer xs]`,
124
+ ` ? 'path' extends keyof x`,
125
+ ` ? x['path'] extends Path`,
126
+ ` ? 'input' extends keyof x`,
127
+ ` ? x['input']`,
128
+ ` : never`,
129
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<Path, xs>`,
130
+ ` : never`,
131
+ ` : never`,
132
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, A = InterfaceType> = A extends []`,
133
+ ` ? []`,
134
+ ` : A extends [infer x, ...infer xs]`,
135
+ ` ? 'path' extends keyof x`,
136
+ ` ? x['path'] extends Path`,
137
+ ` ? 'method' extends keyof x`,
138
+ ` ? x['method']`,
139
+ ` : never`,
140
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<Path, xs>`,
141
+ ` : never`,
142
+ ` : never`,
143
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
144
+ ` ? []`,
145
+ ` : A extends [infer x, ...infer xs]`,
146
+ ` ? 'path' extends keyof x`,
147
+ ` ? x['path'] extends Path`,
148
+ ` ? 'successOutput' extends keyof x`,
149
+ ` ? x['successOutput']`,
150
+ ` : never`,
151
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<Path, xs>`,
152
+ ` : never`,
153
+ ` : never`,
154
+ `type \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, A = InterfaceType> = A extends []`,
155
+ ` ? []`,
156
+ ` : A extends [infer x, ...infer xs]`,
157
+ ` ? 'path' extends keyof x`,
158
+ ` ? x['path'] extends Path`,
159
+ ` ? 'errorOutput' extends keyof x`,
160
+ ` ? x['errorOutput']`,
161
+ ` : never`,
162
+ ` : \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<Path, xs>`,
163
+ ` : never`,
164
+ ` : never`,
165
+ ``,
166
+ `export type \u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<\u6240\u6709\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
167
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
168
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
169
+ ` \u65B9\u6CD5: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u65B9\u6CD5<\u8DEF\u5F84>,`,
170
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
171
+ `export type Get\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Get\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
172
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
173
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
174
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
175
+ `export type Post\u8BF7\u6C42\u540E\u7AEF\u51FD\u6570\u7C7B\u578B = <\u8DEF\u5F84 extends \u5143\u7EC4\u8F6C\u8054\u5408<Post\u63A5\u53E3\u8DEF\u5F84\u4EEC>>(`,
176
+ ` \u8DEF\u5F84: \u8DEF\u5F84,`,
177
+ ` \u53C2\u6570: \u4ECE\u8DEF\u5F84\u83B7\u5F97\u53C2\u6570<\u8DEF\u5F84>,`,
178
+ `) => Promise<\u4ECE\u8DEF\u5F84\u83B7\u5F97\u6B63\u786E\u8FD4\u56DE<\u8DEF\u5F84> | \u4ECE\u8DEF\u5F84\u83B7\u5F97\u9519\u8BEF\u8FD4\u56DE<\u8DEF\u5F84>>`,
179
+ ""
180
+ ];
181
+ fs.writeFileSync(outputPathAbs, code.join("\n"));
182
+ await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
183
+ }
184
+
185
+ export {
186
+ main
187
+ };
package/dist/esm/index.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  表单解析插件
3
3
  } from "./chunk-5UUMGDDD.js";
4
- import {
5
- 服务器
6
- } from "./chunk-4PVN4NSU.js";
7
4
  import {
8
5
  正确JSON结果,
9
6
  正确结果,
@@ -15,6 +12,9 @@ import {
15
12
  import {
16
13
  测试
17
14
  } from "./chunk-I4WZG5LK.js";
15
+ import {
16
+ 服务器
17
+ } from "./chunk-4PVN4NSU.js";
18
18
  import {
19
19
  接口类型
20
20
  } from "./chunk-SF5Z34AP.js";
@@ -12,7 +12,7 @@ declare class JSON解析插件<Result extends z.ZodObject<{
12
12
  }
13
13
  type 任意JSON解析插件 = JSON解析插件<any>;
14
14
  type 任意JSON解析插件项 = _____<任意JSON解析插件>;
15
- type 合并JSON插件结果<Arr extends Array<_____$1>> = Arr extends [] ? {} : Arr extends [infer x, ...infer xs] ? x extends infer 插件项 ? xs extends Array<_____$1> ? 插件项 extends 任意JSON解析插件项 ? z.infer<_______<插件项>>['body'] & ______<xs> : {} : {} : {} : {};
15
+ type 合并JSON插件结果<Arr extends Array<_____$1>> = Arr extends [] ? {} : Arr extends [infer x, ...infer xs] ? x extends infer 插件项 ? xs extends Array<_____$1> ? 插件项 extends 任意JSON解析插件项 ? z.infer<_______<插件项>>['body'] & ______<xs> : 合并JSON插件结果<xs> : {} : {} : {};
16
16
  type 从接口类型获得JSON参数<接口类型描述> = 合并JSON插件结果<_______$1<接口类型描述>>;
17
17
 
18
18
  export { JSON解析插件, type 从接口类型获得JSON参数, type 任意JSON解析插件, type 任意JSON解析插件项, type 合并JSON插件结果 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/net-core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": "./dist/cjs/index.cjs",
@@ -1,93 +0,0 @@
1
- import {
2
- calcCode
3
- } from "./chunk-IRKJYOPK.js";
4
-
5
- // src/bin/gen-type/index.ts
6
- import { randomUUID } from "node:crypto";
7
- import fs, { existsSync, mkdirSync } from "node:fs";
8
- import path from "node:path";
9
- import ts from "typescript";
10
- import { Log } from "@lsby/ts-log";
11
- async function main(tsconfigPath, apiFolderPath, outputPath) {
12
- var log = new Log("@lsby:net-core").extend("gen-type");
13
- await log.debug("\u51C6\u5907\u751F\u6210\u7C7B\u578B\u6587\u4EF6...");
14
- const tsconfigJson = ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, "utf8"));
15
- if (tsconfigJson.error) {
16
- throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
17
- }
18
- const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfigJson.config, ts.sys, path.resolve(tsconfigPath, ".."));
19
- await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...");
20
- const projectHost = ts.createCompilerHost(parsedTsconfig.options);
21
- const project = ts.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
22
- await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...");
23
- const allSourceFiles = project.getSourceFiles();
24
- const apiSourceFiles = allSourceFiles.filter((sourceFile) => {
25
- return new RegExp(`${apiFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(path.resolve(sourceFile.fileName));
26
- });
27
- await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3...", apiSourceFiles.length);
28
- const apiTypeCalcFileNames = apiSourceFiles.map(
29
- (sourceFile) => sourceFile.fileName.replace("type.ts", `type-calculate-${randomUUID()}.ts`)
30
- );
31
- const apiTypeCalcFiles = apiTypeCalcFileNames.map((filename) => {
32
- return {
33
- name: filename,
34
- sourceFile: ts.createSourceFile(filename, calcCode, ts.ScriptTarget.Latest)
35
- };
36
- });
37
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u8BA1\u7B97\u6587\u4EF6...");
38
- const newProject = ts.createProgram({
39
- rootNames: [...parsedTsconfig.fileNames, ...apiTypeCalcFileNames],
40
- options: parsedTsconfig.options,
41
- host: {
42
- ...projectHost,
43
- getSourceFile: (filename) => {
44
- const apiTypeCalcSourceFile = apiTypeCalcFiles.find(
45
- (apiTypeCalcSourceFile2) => apiTypeCalcSourceFile2.name === filename
46
- );
47
- if (apiTypeCalcSourceFile !== void 0) {
48
- return apiTypeCalcSourceFile.sourceFile;
49
- }
50
- return project.getSourceFile(filename);
51
- }
52
- },
53
- oldProgram: project
54
- });
55
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE...");
56
- const check = newProject.getTypeChecker();
57
- await log.debug("\u6210\u529F\u751F\u6210\u865A\u62DF\u9879\u76EE\u7C7B\u578B\u68C0\u67E5\u5668...");
58
- const result = [];
59
- for (var index = 0; index < apiSourceFiles.length; index++) {
60
- var apiSourceFile = apiSourceFiles[index];
61
- if (apiSourceFile == null)
62
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
63
- await log.info(`\u5904\u7406\uFF08${index + 1} / ${apiSourceFiles.length}\uFF09\uFF1A${apiSourceFile.fileName}`);
64
- const apiCalcSourceFile = apiTypeCalcFiles[index]?.sourceFile;
65
- if (apiCalcSourceFile === void 0) {
66
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
67
- }
68
- for (const node of apiCalcSourceFile.statements) {
69
- if (ts.isExportAssignment(node) && node.isExportEquals === void 0) {
70
- const apiType = check.getTypeAtLocation(node.expression);
71
- const typeString = check.typeToString(
72
- apiType,
73
- void 0,
74
- ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.AllowUniqueESSymbolType | ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
75
- );
76
- result.push(typeString);
77
- }
78
- }
79
- }
80
- await log.debug("\u6210\u529F\u5904\u7406\u6240\u6709\u63A5\u53E3...");
81
- const outputPathAbs = path.resolve(outputPath);
82
- var outDir = path.dirname(outputPathAbs);
83
- if (!existsSync(outDir)) {
84
- mkdirSync(outDir, { recursive: true });
85
- }
86
- fs.writeFileSync(outputPathAbs, `export type InterfaceType = [${result.join(",")}]
87
- `);
88
- await log.debug("\u751F\u6210\u6210\u529F\uFF1A%o", outputPathAbs);
89
- }
90
-
91
- export {
92
- main
93
- };