@lsby/net-core 0.3.22 → 0.3.23

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 (131) hide show
  1. package/dist/bin/gen-list/bin.cjs +93 -47
  2. package/dist/bin/gen-list/index.cjs +93 -47
  3. package/dist/bin/gen-list/index.d.cts +1 -1
  4. package/dist/bin/gen-test/bin.cjs +90 -54
  5. package/dist/bin/gen-test/index.cjs +90 -54
  6. package/dist/bin/gen-test/index.d.cts +1 -1
  7. package/dist/bin/gen-type/bin.cjs +96 -93
  8. package/dist/bin/gen-type/index.cjs +96 -93
  9. package/dist/bin/gen-type/index.d.cts +1 -1
  10. package/dist/cjs/{interface/action → action}/action.cjs +1 -1
  11. package/dist/cjs/bin/gen-list/bin.cjs +93 -47
  12. package/dist/cjs/bin/gen-list/index.cjs +93 -47
  13. package/dist/cjs/bin/gen-list/index.d.cts +1 -1
  14. package/dist/cjs/bin/gen-test/bin.cjs +90 -54
  15. package/dist/cjs/bin/gen-test/index.cjs +90 -54
  16. package/dist/cjs/bin/gen-test/index.d.cts +1 -1
  17. package/dist/cjs/bin/gen-type/bin.cjs +96 -93
  18. package/dist/cjs/bin/gen-type/index.cjs +96 -93
  19. package/dist/cjs/bin/gen-type/index.d.cts +1 -1
  20. package/dist/cjs/index.cjs +62 -122
  21. package/dist/cjs/index.d.cts +12 -15
  22. package/dist/cjs/{extend/api-json-base.cjs → interface/extend/json-base.cjs} +54 -54
  23. package/dist/cjs/{extend/api-json-base.d.cts → interface/extend/json-base.d.cts} +8 -8
  24. package/dist/cjs/{extend/api-json-wrap.cjs → interface/extend/json-wrap.cjs} +79 -75
  25. package/dist/cjs/interface/extend/json-wrap.d.cts +26 -0
  26. package/dist/cjs/interface/{inst/interface-abstract.cjs → interface-inst.cjs} +9 -9
  27. package/dist/cjs/interface/interface-inst.d.cts +18 -0
  28. package/dist/cjs/{test/test-abstract.cjs → interface/interface-test.cjs} +7 -7
  29. package/dist/{esm/test/test-abstract.d.ts → cjs/interface/interface-test.d.cts} +2 -2
  30. package/dist/cjs/interface/{type/interface-type.cjs → interface-type.cjs} +2 -9
  31. package/dist/cjs/interface/interface-type.d.cts +28 -0
  32. package/dist/cjs/plugin/{chinese-path.cjs → extend/chinese-path.cjs} +3 -3
  33. package/dist/cjs/plugin/{chinese-path.d.cts → extend/chinese-path.d.cts} +1 -1
  34. package/dist/cjs/plugin/{custom-data.cjs → extend/custom-data.cjs} +3 -3
  35. package/dist/cjs/plugin/{custom-data.d.cts → extend/custom-data.d.cts} +1 -1
  36. package/dist/cjs/plugin/{json.cjs → extend/json.cjs} +4 -4
  37. package/dist/cjs/plugin/{json.d.cts → extend/json.d.cts} +2 -2
  38. package/dist/cjs/plugin/{urlencoded.cjs → extend/urlencoded.cjs} +4 -4
  39. package/dist/cjs/plugin/{urlencoded.d.cts → extend/urlencoded.d.cts} +1 -1
  40. package/dist/cjs/{interface → plugin}/plug.cjs +1 -1
  41. package/dist/cjs/server/server.d.cts +5 -5
  42. package/dist/esm/{interface/action → action}/action.js +1 -1
  43. package/dist/esm/bin/gen-list/bin.js +1 -1
  44. package/dist/esm/bin/gen-list/index.d.ts +1 -1
  45. package/dist/esm/bin/gen-list/index.js +1 -1
  46. package/dist/esm/bin/gen-test/bin.js +1 -1
  47. package/dist/esm/bin/gen-test/index.d.ts +1 -1
  48. package/dist/esm/bin/gen-test/index.js +1 -1
  49. package/dist/esm/bin/gen-type/bin.js +1 -2
  50. package/dist/esm/bin/gen-type/index.d.ts +1 -1
  51. package/dist/esm/bin/gen-type/index.js +1 -2
  52. package/dist/esm/{chunk-P6PGPAMW.js → chunk-2MN4G2DG.js} +2 -2
  53. package/dist/esm/chunk-3WT6TRYJ.js +37 -0
  54. package/dist/esm/chunk-B5W4H32C.js +112 -0
  55. package/dist/esm/chunk-IZ623QVE.js +11 -0
  56. package/dist/esm/{chunk-XG4VZZOX.js → chunk-KW3M3VXP.js} +2 -2
  57. package/dist/esm/chunk-MMAAGHJW.js +214 -0
  58. package/dist/esm/{chunk-KSZE2DTR.js → chunk-N4NY37XI.js} +1 -1
  59. package/dist/esm/{chunk-VJ4ORZR3.js → chunk-P4TLIJX4.js} +5 -5
  60. package/dist/esm/{chunk-S7GRYORG.js → chunk-P6ML63XI.js} +6 -6
  61. package/dist/esm/{chunk-CMHISRDG.js → chunk-SF5Z34AP.js} +2 -7
  62. package/dist/esm/{chunk-XRV64MDF.js → chunk-SFNQ5AWH.js} +3 -3
  63. package/dist/esm/chunk-TMRT3MBS.js +113 -0
  64. package/dist/esm/{chunk-N7G2H6GB.js → chunk-V3S5HDZD.js} +1 -1
  65. package/dist/esm/{chunk-5UUMGDDD.js → chunk-XTHURYQM.js} +3 -3
  66. package/dist/esm/index.d.ts +12 -15
  67. package/dist/esm/index.js +32 -46
  68. package/dist/esm/{extend/api-json-base.d.ts → interface/extend/json-base.d.ts} +8 -8
  69. package/dist/esm/interface/extend/json-base.js +10 -0
  70. package/dist/esm/interface/extend/json-wrap.d.ts +26 -0
  71. package/dist/esm/interface/extend/json-wrap.js +13 -0
  72. package/dist/esm/interface/interface-inst.d.ts +18 -0
  73. package/dist/esm/interface/interface-inst.js +7 -0
  74. package/dist/{cjs/test/test-abstract.d.cts → esm/interface/interface-test.d.ts} +2 -2
  75. package/dist/esm/interface/interface-test.js +6 -0
  76. package/dist/esm/interface/interface-type.d.ts +28 -0
  77. package/dist/esm/interface/interface-type.js +6 -0
  78. package/dist/esm/plugin/{chinese-path.d.ts → extend/chinese-path.d.ts} +1 -1
  79. package/dist/esm/plugin/{chinese-path.js → extend/chinese-path.js} +2 -2
  80. package/dist/esm/plugin/{custom-data.d.ts → extend/custom-data.d.ts} +1 -1
  81. package/dist/esm/plugin/{custom-data.js → extend/custom-data.js} +2 -2
  82. package/dist/esm/plugin/{json.d.ts → extend/json.d.ts} +2 -2
  83. package/dist/esm/plugin/extend/json.js +8 -0
  84. package/dist/esm/plugin/{urlencoded.d.ts → extend/urlencoded.d.ts} +1 -1
  85. package/dist/esm/plugin/{urlencoded.js → extend/urlencoded.js} +2 -2
  86. package/dist/esm/{interface → plugin}/plug.js +1 -1
  87. package/dist/esm/server/server.d.ts +5 -5
  88. package/package.json +4 -2
  89. package/dist/bin/gen-type/calc-code.cjs +0 -53
  90. package/dist/bin/gen-type/calc-code.d.cts +0 -3
  91. package/dist/cjs/bin/gen-type/calc-code.cjs +0 -53
  92. package/dist/cjs/bin/gen-type/calc-code.d.cts +0 -3
  93. package/dist/cjs/extend/api-json-wrap.d.cts +0 -55
  94. package/dist/cjs/interface/inst/interface-abstract.d.cts +0 -18
  95. package/dist/cjs/interface/inst/interface.cjs +0 -167
  96. package/dist/cjs/interface/inst/interface.d.cts +0 -18
  97. package/dist/cjs/interface/type/interface-type-abstract.cjs +0 -31
  98. package/dist/cjs/interface/type/interface-type-abstract.d.cts +0 -21
  99. package/dist/cjs/interface/type/interface-type.d.cts +0 -22
  100. package/dist/cjs/test/test.cjs +0 -60
  101. package/dist/cjs/test/test.d.cts +0 -19
  102. package/dist/esm/bin/gen-type/calc-code.d.ts +0 -3
  103. package/dist/esm/bin/gen-type/calc-code.js +0 -6
  104. package/dist/esm/chunk-34QVQSKM.js +0 -20
  105. package/dist/esm/chunk-4KSHDKSP.js +0 -11
  106. package/dist/esm/chunk-CSZNLNB5.js +0 -76
  107. package/dist/esm/chunk-DMQXYTFQ.js +0 -7
  108. package/dist/esm/chunk-DQX4L6GK.js +0 -187
  109. package/dist/esm/chunk-FLIKJZGI.js +0 -29
  110. package/dist/esm/chunk-LSG6UGUR.js +0 -54
  111. package/dist/esm/chunk-PIYVLQLM.js +0 -27
  112. package/dist/esm/chunk-YYOST4AX.js +0 -67
  113. package/dist/esm/extend/api-json-base.js +0 -10
  114. package/dist/esm/extend/api-json-wrap.d.ts +0 -55
  115. package/dist/esm/extend/api-json-wrap.js +0 -15
  116. package/dist/esm/interface/inst/interface-abstract.d.ts +0 -18
  117. package/dist/esm/interface/inst/interface-abstract.js +0 -7
  118. package/dist/esm/interface/inst/interface.d.ts +0 -18
  119. package/dist/esm/interface/inst/interface.js +0 -8
  120. package/dist/esm/interface/type/interface-type-abstract.d.ts +0 -21
  121. package/dist/esm/interface/type/interface-type-abstract.js +0 -6
  122. package/dist/esm/interface/type/interface-type.d.ts +0 -22
  123. package/dist/esm/interface/type/interface-type.js +0 -7
  124. package/dist/esm/plugin/json.js +0 -8
  125. package/dist/esm/test/test-abstract.js +0 -6
  126. package/dist/esm/test/test.d.ts +0 -19
  127. package/dist/esm/test/test.js +0 -7
  128. /package/dist/cjs/{interface/action → action}/action.d.cts +0 -0
  129. /package/dist/cjs/{interface → plugin}/plug.d.cts +0 -0
  130. /package/dist/esm/{interface/action → action}/action.d.ts +0 -0
  131. /package/dist/esm/{interface → plugin}/plug.d.ts +0 -0
@@ -1,187 +0,0 @@
1
- import {
2
- calcCode
3
- } from "./chunk-FLIKJZGI.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
- };
@@ -1,29 +0,0 @@
1
- // src/bin/gen-type/calc-code.ts
2
- var calcCode = `
3
- import type { z } from 'zod'
4
- import type { \u5408\u5E76JSON\u63D2\u4EF6\u7ED3\u679C, \u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B } from '@lsby/net-core'
5
- import exportedApiSchema from './type'
6
-
7
- type Api =
8
- typeof exportedApiSchema extends \u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B<
9
- infer Path,
10
- infer Method,
11
- infer PreApis,
12
- infer SuccessSchema,
13
- infer ErrorSchema
14
- >
15
- ? {
16
- path: Path
17
- method: Method
18
- input: \u5408\u5E76JSON\u63D2\u4EF6\u7ED3\u679C<PreApis>
19
- successOutput: z.infer<SuccessSchema>
20
- errorOutput: z.infer<ErrorSchema>
21
- }
22
- : never
23
-
24
- export default Api
25
- `;
26
-
27
- export {
28
- calcCode
29
- };
@@ -1,54 +0,0 @@
1
- import {
2
- 接口类型抽象类
3
- } from "./chunk-DMQXYTFQ.js";
4
- import {
5
- API接口基类
6
- } from "./chunk-4KSHDKSP.js";
7
- import {
8
- 正确JSON结果,
9
- 错误JSON结果
10
- } from "./chunk-IPDMEQ3O.js";
11
-
12
- // src/extend/api-json-wrap.ts
13
- import { z } from "zod";
14
- var \u5305\u88C5\u7684\u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B = class extends \u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B {
15
- };
16
- var \u5305\u88C5\u7684\u63A5\u53E3\u7C7B\u578B = class extends \u5305\u88C5\u7684\u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B {
17
- constructor(path, method, \u63D2\u4EF6\u4EEC, \u6B63\u786E\u8FD4\u56DE\u7C7B\u578B, \u9519\u8BEF\u8FD4\u56DE\u7C7B\u578B) {
18
- super();
19
- this.path = path;
20
- this.method = method;
21
- this.\u63D2\u4EF6\u4EEC = \u63D2\u4EF6\u4EEC;
22
- this.\u6B63\u786E\u8FD4\u56DE\u7C7B\u578B = \u6B63\u786E\u8FD4\u56DE\u7C7B\u578B;
23
- this.\u9519\u8BEF\u8FD4\u56DE\u7C7B\u578B = \u9519\u8BEF\u8FD4\u56DE\u7C7B\u578B;
24
- }
25
- \u83B7\u5F97\u8DEF\u5F84() {
26
- return this.path;
27
- }
28
- \u83B7\u5F97\u65B9\u6CD5() {
29
- return this.method;
30
- }
31
- \u83B7\u5F97\u63D2\u4EF6\u4EEC() {
32
- return this.\u63D2\u4EF6\u4EEC;
33
- }
34
- \u83B7\u5F97\u6B63\u786E\u7ED3\u679C\u7C7B\u578B() {
35
- return z.object({ status: z.literal("success"), data: this.\u6B63\u786E\u8FD4\u56DE\u7C7B\u578B });
36
- }
37
- \u83B7\u5F97\u9519\u8BEF\u7ED3\u679C\u7C7B\u578B() {
38
- return z.object({ status: z.literal("fail"), data: this.\u9519\u8BEF\u8FD4\u56DE\u7C7B\u578B });
39
- }
40
- };
41
- var JSON\u63A5\u53E3\u5305\u88C5\u57FA\u7C7B = class extends API\u63A5\u53E3\u57FA\u7C7B {
42
- async API\u5B9E\u73B0(\u53C2\u6570) {
43
- var c = await this.\u4E1A\u52A1\u884C\u4E3A\u5B9E\u73B0(\u53C2\u6570);
44
- if (c.isLeft())
45
- return new \u9519\u8BEFJSON\u7ED3\u679C({ status: "fail", data: c.assertLeft().getLeft() });
46
- return new \u6B63\u786EJSON\u7ED3\u679C({ status: "success", data: c.assertRight().getRight() });
47
- }
48
- };
49
-
50
- export {
51
- 包装的接口类型抽象类,
52
- 包装的接口类型,
53
- JSON接口包装基类
54
- };
@@ -1,27 +0,0 @@
1
- import {
2
- 测试抽象类
3
- } from "./chunk-XRV64MDF.js";
4
-
5
- // src/test/test.ts
6
- var \u6D4B\u8BD5 = class extends \u6D4B\u8BD5\u62BD\u8C61\u7C7B {
7
- constructor(\u63A5\u53E3\u7C7B\u578B, \u524D\u7F6E, \u4E2D\u7F6E, \u540E\u7F6E) {
8
- super();
9
- this.\u63A5\u53E3\u7C7B\u578B = \u63A5\u53E3\u7C7B\u578B;
10
- this.\u524D\u7F6E = \u524D\u7F6E;
11
- this.\u4E2D\u7F6E = \u4E2D\u7F6E;
12
- this.\u540E\u7F6E = \u540E\u7F6E;
13
- }
14
- \u524D\u7F6E\u5B9E\u73B0() {
15
- return this.\u524D\u7F6E();
16
- }
17
- \u4E2D\u7F6E\u5B9E\u73B0() {
18
- return this.\u4E2D\u7F6E();
19
- }
20
- \u540E\u7F6E\u5B9E\u73B0(\u4E2D\u7F6E\u7ED3\u679C) {
21
- return this.\u540E\u7F6E(\u4E2D\u7F6E\u7ED3\u679C);
22
- }
23
- };
24
-
25
- export {
26
- 测试
27
- };
@@ -1,67 +0,0 @@
1
- // src/bin/gen-list/index.ts
2
- import fs, { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
- import path from "node:path";
4
- import ts from "typescript";
5
- import { Log } from "@lsby/ts-log";
6
- async function main(tsconfigPath, interfaceFolderPath, outFilePath) {
7
- var log = new Log("@lsby:net-core").extend("gen-list");
8
- await log.debug("\u51C6\u5907\u751F\u6210\u63A5\u53E3\u5217\u8868...");
9
- const \u9879\u76EE\u6839\u8DEF\u5F84 = path.dirname(tsconfigPath);
10
- const tsconfigJson = ts.parseConfigFileTextToJson(tsconfigPath, fs.readFileSync(tsconfigPath, "utf8"));
11
- if (tsconfigJson.error) {
12
- throw new Error("\u65E0\u6CD5\u89E3\u6790 tsconfig.json");
13
- }
14
- const parsedTsconfig = ts.parseJsonConfigFileContent(tsconfigJson.config, ts.sys, path.resolve(tsconfigPath, ".."));
15
- await log.debug("\u6210\u529F\u89E3\u6790 tsconfig \u6587\u4EF6...");
16
- const projectHost = ts.createCompilerHost(parsedTsconfig.options);
17
- const project = ts.createProgram(parsedTsconfig.fileNames, parsedTsconfig.options, projectHost);
18
- await log.debug("\u6210\u529F\u8BFB\u53D6\u9879\u76EE...");
19
- const _check = project.getTypeChecker();
20
- const \u6240\u6709\u6E90\u6587\u4EF6 = project.getSourceFiles();
21
- const \u63A5\u53E3\u7C7B\u578B\u6587\u4EF6\u4EEC = \u6240\u6709\u6E90\u6587\u4EF6.filter((sourceFile) => {
22
- return new RegExp(`${interfaceFolderPath.replaceAll("\\", "\\\\")}.*type.ts`).test(
23
- path.resolve(sourceFile.fileName)
24
- );
25
- });
26
- const \u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6\u4EEC = \u6240\u6709\u6E90\u6587\u4EF6.filter((sourceFile) => {
27
- return new RegExp(`${interfaceFolderPath.replaceAll("\\", "\\\\")}.*index.ts`).test(
28
- path.resolve(sourceFile.fileName)
29
- );
30
- });
31
- await log.debug("\u627E\u5230 %o \u4E2A\u63A5\u53E3", \u63A5\u53E3\u7C7B\u578B\u6587\u4EF6\u4EEC.length);
32
- const \u5F15\u5165\u533A = [];
33
- const \u4EE3\u7801\u533A = [];
34
- for (var i = 0; i < \u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6\u4EEC.length; i++) {
35
- var \u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6 = \u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6\u4EEC[i];
36
- if (\u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6 == null)
37
- throw new Error("\u975E\u9884\u671F\u7684\u6570\u7EC4\u8D8A\u754C");
38
- const filenameRelativeToApiFolder = path.relative(interfaceFolderPath, \u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6.fileName).replaceAll("\\", "/");
39
- const importName = filenameRelativeToApiFolder.replaceAll("/", "_").replaceAll(".ts", "").replaceAll("./", "").replaceAll("-", "_");
40
- const filenameRelativeToProjectRoot = path.relative(\u9879\u76EE\u6839\u8DEF\u5F84, \u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6.fileName).replaceAll("\\", "/").replaceAll(".ts", "");
41
- const outputFolderRelativeToProjectRoot = path.relative(path.dirname(outFilePath), \u9879\u76EE\u6839\u8DEF\u5F84).replaceAll("\\", "/");
42
- const importPath = path.join(outputFolderRelativeToProjectRoot, filenameRelativeToProjectRoot).replaceAll("\\", "/");
43
- await log.info(`\u5904\u7406\uFF08${i + 1} / ${\u63A5\u53E3\u5B9E\u73B0\u6587\u4EF6\u4EEC.length}\uFF09\uFF1A${filenameRelativeToApiFolder}`);
44
- \u5F15\u5165\u533A.push(`import * as ${importName} from '${importPath}'`);
45
- \u4EE3\u7801\u533A.push(`${importName}.default`);
46
- }
47
- const finalTestFile = [
48
- // ..
49
- `import { \u4EFB\u610F\u63A5\u53E3 } from '@lsby/net-core'`,
50
- "",
51
- ...\u5F15\u5165\u533A,
52
- "",
53
- `export var interfaceList: \u4EFB\u610F\u63A5\u53E3[] = [
54
- ${\u4EE3\u7801\u533A.map((a) => ` ${a}`).join(",\n")}
55
- ]`,
56
- ""
57
- ].join("\n");
58
- var outDir = path.dirname(outFilePath);
59
- if (!existsSync(outDir)) {
60
- mkdirSync(outDir, { recursive: true });
61
- }
62
- writeFileSync(outFilePath, finalTestFile);
63
- }
64
-
65
- export {
66
- main
67
- };
@@ -1,10 +0,0 @@
1
- import {
2
- JSON接口基类
3
- } from "../chunk-S7GRYORG.js";
4
- import "../chunk-4KSHDKSP.js";
5
- import "../chunk-N7G2H6GB.js";
6
- import "../chunk-IPDMEQ3O.js";
7
- import "../chunk-AHCV3LQ7.js";
8
- export {
9
- JSON\u63A5\u53E3\u57FA\u7C7B
10
- };
@@ -1,55 +0,0 @@
1
- import { z } from 'zod';
2
- import { Either } from '@lsby/ts-fp-data';
3
- import { API接口基类 as API____, 计算实现参数 as ______ } from '../interface/inst/interface-abstract.js';
4
- import { 插件项类型 as _____, 合并插件结果 as ______$1 } from '../interface/plug.js';
5
- import { 接口类型抽象类 as _______, 接口类型错误结果 as ________, 接口类型正确结果 as ________$1, 接口类型插件们 as _______$1 } from '../interface/type/interface-type-abstract.js';
6
- import { 正确结果 as ____, 错误结果 as ____$1 } from '../result/result.js';
7
- import '../interface/action/action.js';
8
- import 'express';
9
-
10
- declare abstract class 包装的接口类型抽象类<路径 extends string, 方法 extends 'get' | 'post', 插件们 extends Array<_____>, 正确返回类型 extends z.ZodTypeAny, 错误返回类型 extends z.ZodTypeAny> extends _______<路径, 方法, 插件们, z.ZodObject<{
11
- status: z.ZodLiteral<'success'>;
12
- data: 正确返回类型;
13
- }>, z.ZodObject<{
14
- status: z.ZodLiteral<'fail'>;
15
- data: 错误返回类型;
16
- }>> {
17
- abstract 获得路径(): 路径;
18
- abstract 获得方法(): 方法;
19
- abstract 获得插件们(): [...插件们];
20
- abstract 获得正确结果类型(): z.ZodObject<{
21
- status: z.ZodLiteral<'success'>;
22
- data: 正确返回类型;
23
- }>;
24
- abstract 获得错误结果类型(): z.ZodObject<{
25
- status: z.ZodLiteral<'fail'>;
26
- data: 错误返回类型;
27
- }>;
28
- }
29
- type 任意的包装的接口类型 = 包装的接口类型抽象类<any, any, any, any, any>;
30
- declare class 包装的接口类型<路径 extends string, 方法 extends 'get' | 'post', 插件们 extends Array<_____>, 正确返回类型 extends z.ZodTypeAny, 错误返回类型 extends z.ZodTypeAny> extends 包装的接口类型抽象类<路径, 方法, 插件们, 正确返回类型, 错误返回类型> {
31
- private path;
32
- private method;
33
- private 插件们;
34
- private 正确返回类型;
35
- private 错误返回类型;
36
- constructor(path: 路径, method: 方法, 插件们: [...插件们], 正确返回类型: 正确返回类型, 错误返回类型: 错误返回类型);
37
- 获得路径(): 路径;
38
- 获得方法(): 方法;
39
- 获得插件们(): [...插件们];
40
- 获得正确结果类型(): z.ZodObject<{
41
- status: z.ZodLiteral<'success'>;
42
- data: 正确返回类型;
43
- }>;
44
- 获得错误结果类型(): z.ZodObject<{
45
- status: z.ZodLiteral<'fail'>;
46
- data: 错误返回类型;
47
- }>;
48
- }
49
- type 计算JSON实现返回<接口类型描述> = Promise<Either<z.infer<________<接口类型描述>>['data'], z.infer<________$1<接口类型描述>>['data']>>;
50
- declare abstract class JSON接口包装基类<接口类型描述 extends 任意的包装的接口类型> extends API____<接口类型描述> {
51
- protected abstract 业务行为实现(参数: ______<接口类型描述>): 计算JSON实现返回<接口类型描述>;
52
- API实现(参数: ______$1<_______$1<接口类型描述>>): Promise<____<z.infer<________$1<接口类型描述>>> | ____$1<z.infer<________<接口类型描述>>>>;
53
- }
54
-
55
- export { JSON接口包装基类, 包装的接口类型, 包装的接口类型抽象类, type 计算JSON实现返回 };
@@ -1,15 +0,0 @@
1
- import {
2
- JSON接口包装基类,
3
- 包装的接口类型,
4
- 包装的接口类型抽象类
5
- } from "../chunk-LSG6UGUR.js";
6
- import "../chunk-DMQXYTFQ.js";
7
- import "../chunk-4KSHDKSP.js";
8
- import "../chunk-N7G2H6GB.js";
9
- import "../chunk-IPDMEQ3O.js";
10
- import "../chunk-AHCV3LQ7.js";
11
- export {
12
- JSON\u63A5\u53E3\u5305\u88C5\u57FA\u7C7B,
13
- \u5305\u88C5\u7684\u63A5\u53E3\u7C7B\u578B,
14
- \u5305\u88C5\u7684\u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B
15
- };
@@ -1,18 +0,0 @@
1
- import { z } from 'zod';
2
- import { Either } from '@lsby/ts-fp-data';
3
- import { 正确结果 as ____$1, 错误结果 as ____$2 } from '../../result/result.js';
4
- import { 业务行为 as ____ } from '../action/action.js';
5
- import { 合并插件结果 as ______ } from '../plug.js';
6
- import { 接口类型插件们 as _______, 接口类型错误结果 as ________, 接口类型正确结果 as ________$1, 任意接口类型 as ______$1 } from '../type/interface-type-abstract.js';
7
- import 'express';
8
-
9
- type 计算实现参数<接口类型描述> = ______<_______<接口类型描述>>;
10
- type 计算实现返回<接口类型描述> = Promise<Either<z.infer<________<接口类型描述>>, z.infer<________$1<接口类型描述>>>>;
11
- declare abstract class API接口基类<接口类型描述 extends ______$1> extends ____<计算实现参数<接口类型描述>, z.infer<________<接口类型描述>>, z.infer<________$1<接口类型描述>>> {
12
- protected abstract 业务行为实现(参数: 计算实现参数<接口类型描述>): 计算实现返回<接口类型描述>;
13
- abstract 获得API类型(): 接口类型描述;
14
- abstract API实现(参数: 计算实现参数<接口类型描述>): Promise<____$1<z.infer<________$1<接口类型描述>>> | ____$2<z.infer<________<接口类型描述>>>>;
15
- }
16
- type 任意接口 = API接口基类<any>;
17
-
18
- export { API接口基类, type 任意接口, type 计算实现参数, type 计算实现返回 };
@@ -1,7 +0,0 @@
1
- import {
2
- API接口基类
3
- } from "../../chunk-4KSHDKSP.js";
4
- import "../../chunk-N7G2H6GB.js";
5
- export {
6
- API\u63A5\u53E3\u57FA\u7C7B
7
- };
@@ -1,18 +0,0 @@
1
- import { z } from 'zod';
2
- import { Either } from '@lsby/ts-fp-data';
3
- import { 正确结果 as ____, 错误结果 as ____$1 } from '../../result/result.js';
4
- import { 插件项类型 as _____, 合并插件结果 as ______ } from '../plug.js';
5
- import { 接口类型抽象类 as _______ } from '../type/interface-type-abstract.js';
6
- import { API接口基类 as API____ } from './interface-abstract.js';
7
- import 'express';
8
- import '../action/action.js';
9
-
10
- declare class API接口<路径 extends string, 方法 extends 'get' | 'post', 插件们 extends Array<_____>, 正确返回类型 extends z.ZodTypeAny, 错误返回类型 extends z.ZodTypeAny> extends API____<_______<路径, 方法, 插件们, 正确返回类型, 错误返回类型>> {
11
- private 接口类型;
12
- API实现: (参数: ______<插件们>) => Promise<____<z.infer<正确返回类型>> | ____$1<z.infer<错误返回类型>>>;
13
- protected 业务行为实现: (插件结果: ______<插件们>) => Promise<Either<z.infer<错误返回类型>, z.infer<正确返回类型>>>;
14
- constructor(接口类型: _______<路径, 方法, 插件们, 正确返回类型, 错误返回类型>, API实现: (参数: ______<插件们>) => Promise<____<z.infer<正确返回类型>> | ____$1<z.infer<错误返回类型>>>, 业务行为实现: (插件结果: ______<插件们>) => Promise<Either<z.infer<错误返回类型>, z.infer<正确返回类型>>>);
15
- 获得API类型(): _______<路径, 方法, 插件们, 正确返回类型, 错误返回类型>;
16
- }
17
-
18
- export { API接口 };
@@ -1,8 +0,0 @@
1
- import {
2
- API接口
3
- } from "../../chunk-34QVQSKM.js";
4
- import "../../chunk-4KSHDKSP.js";
5
- import "../../chunk-N7G2H6GB.js";
6
- export {
7
- API\u63A5\u53E3
8
- };
@@ -1,21 +0,0 @@
1
- import { z } from 'zod';
2
- import { 插件项类型 as _____ } from '../plug.js';
3
- import 'express';
4
- import '@lsby/ts-fp-data';
5
-
6
- type 接口类型路径<A> = A extends 接口类型抽象类<infer A1, infer _A2, infer _A3, infer _A4, infer _A5> ? A1 : never;
7
- type 接口类型方法<A> = A extends 接口类型抽象类<infer _A1, infer A2, infer _A3, infer _A4, infer _A5> ? A2 : never;
8
- type 接口类型插件们<A> = A extends 接口类型抽象类<infer _A1, infer _A2, infer A3, infer _A4, infer _A5> ? A3 : never;
9
- type 接口类型正确结果<A> = A extends 接口类型抽象类<infer _A1, infer _A2, infer _A3, infer A4, infer _A5> ? A4 : never;
10
- type 接口类型错误结果<A> = A extends 接口类型抽象类<infer _A1, infer _A2, infer _A3, infer _A4, infer A5> ? A5 : never;
11
- declare abstract class 接口类型抽象类<路径 extends string, 方法 extends 'get' | 'post', 插件们 extends Array<_____>, 正确结果类型 extends z.ZodTypeAny, 错误结果类型 extends z.ZodTypeAny> {
12
- abstract 获得路径(): 路径;
13
- abstract 获得方法(): 方法;
14
- abstract 获得插件们(): [...插件们];
15
- abstract 获得正确结果类型(): 正确结果类型;
16
- abstract 获得错误结果类型(): 错误结果类型;
17
- }
18
- type 任意接口类型 = 接口类型抽象类<any, any, any, any, any>;
19
- type 获得接口插件们<接口类型描述> = 接口类型描述 extends 接口类型抽象类<any, any, infer 插件, any, any> ? 插件 : never;
20
-
21
- export { type 任意接口类型, 接口类型抽象类, type 接口类型插件们, type 接口类型方法, type 接口类型正确结果, type 接口类型路径, type 接口类型错误结果, type 获得接口插件们 };
@@ -1,6 +0,0 @@
1
- import {
2
- 接口类型抽象类
3
- } from "../../chunk-DMQXYTFQ.js";
4
- export {
5
- \u63A5\u53E3\u7C7B\u578B\u62BD\u8C61\u7C7B
6
- };
@@ -1,22 +0,0 @@
1
- import { z } from 'zod';
2
- import { 插件项类型 as _____ } from '../plug.js';
3
- import { 接口类型抽象类 as _______ } from './interface-type-abstract.js';
4
- import 'express';
5
- import '@lsby/ts-fp-data';
6
-
7
- declare class 接口类型<路径 extends string, 方法 extends 'get' | 'post', 插件们 extends Array<_____>, 正确结果类型 extends z.ZodTypeAny, 错误结果类型 extends z.ZodTypeAny> extends _______<路径, 方法, 插件们, 正确结果类型, 错误结果类型> {
8
- private 路径;
9
- private 方法;
10
- private 插件们;
11
- private 正确结果;
12
- private 错误结果;
13
- protected readonly __类型保持符号?: [路径, 方法, 插件们, 正确结果类型, 错误结果类型];
14
- constructor(路径: 路径, 方法: 方法, 插件们: [...插件们], 正确结果: 正确结果类型, 错误结果: 错误结果类型);
15
- 获得路径(): 路径;
16
- 获得方法(): 方法;
17
- 获得插件们(): [...插件们];
18
- 获得正确结果类型(): 正确结果类型;
19
- 获得错误结果类型(): 错误结果类型;
20
- }
21
-
22
- export { 接口类型 };
@@ -1,7 +0,0 @@
1
- import {
2
- 接口类型
3
- } from "../../chunk-CMHISRDG.js";
4
- import "../../chunk-DMQXYTFQ.js";
5
- export {
6
- \u63A5\u53E3\u7C7B\u578B
7
- };
@@ -1,8 +0,0 @@
1
- import {
2
- JSON解析插件
3
- } from "../chunk-VJ4ORZR3.js";
4
- import "../chunk-AHCV3LQ7.js";
5
- import "../chunk-KSZE2DTR.js";
6
- export {
7
- JSON\u89E3\u6790\u63D2\u4EF6
8
- };
@@ -1,6 +0,0 @@
1
- import {
2
- 测试抽象类
3
- } from "../chunk-XRV64MDF.js";
4
- export {
5
- \u6D4B\u8BD5\u62BD\u8C61\u7C7B
6
- };
@@ -1,19 +0,0 @@
1
- import { 任意接口类型 as ______ } from '../interface/type/interface-type-abstract.js';
2
- import { 测试抽象类 as _____ } from './test-abstract.js';
3
- import 'zod';
4
- import '../interface/plug.js';
5
- import 'express';
6
- import '@lsby/ts-fp-data';
7
-
8
- declare class 测试 extends _____ {
9
- private 接口类型;
10
- protected 前置: () => Promise<void>;
11
- protected 中置: () => Promise<object>;
12
- protected 后置: (中置结果: object) => Promise<void>;
13
- constructor(接口类型: ______, 前置: () => Promise<void>, 中置: () => Promise<object>, 后置: (中置结果: object) => Promise<void>);
14
- 前置实现(): Promise<void>;
15
- 中置实现(): Promise<object>;
16
- 后置实现(中置结果: object): Promise<void>;
17
- }
18
-
19
- export { 测试 };
@@ -1,7 +0,0 @@
1
- import {
2
- 测试
3
- } from "../chunk-PIYVLQLM.js";
4
- import "../chunk-XRV64MDF.js";
5
- export {
6
- \u6D4B\u8BD5
7
- };
File without changes
File without changes