@tuyau/core 0.0.4 → 0.0.6
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/LICENSE.md +9 -0
- package/build/chunk-3KNDPG6Y.js +15 -0
- package/build/commands/commands.json +1 -1
- package/build/commands/generate.d.ts +1 -0
- package/build/commands/generate.js +28 -17
- package/build/index.js +2 -0
- package/build/providers/tuyau_provider.js +2 -0
- package/package.json +19 -33
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
__decorateClass
|
|
15
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commands":[{"commandName":"tuyau:generate","description":"Tuyau generator command","help":"","namespace":"tuyau","aliases":[],"flags":[],"args":[],"options":{"startApp":true},"filePath":"generate.js","absoluteFilePath":"/home/julien/code/adonis/tuyau/packages/core/build/commands/generate.js"}],"version":1}
|
|
1
|
+
{"commands":[{"commandName":"tuyau:generate","description":"Tuyau generator command","help":"","namespace":"tuyau","aliases":[],"flags":[{"name":"verbose","flagName":"verbose","required":false,"type":"boolean","description":"Verbose logs","default":false,"alias":"v"}],"args":[],"options":{"startApp":true},"filePath":"generate.js","absoluteFilePath":"/home/julien/code/adonis/tuyau/packages/core/build/commands/generate.js"}],"version":1}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass
|
|
3
|
+
} from "../chunk-3KNDPG6Y.js";
|
|
4
|
+
|
|
1
5
|
// commands/generate.ts
|
|
2
6
|
import { Project, QuoteKind } from "ts-morph";
|
|
3
|
-
import { BaseCommand } from "@adonisjs/core/ace";
|
|
7
|
+
import { BaseCommand, flags } from "@adonisjs/core/ace";
|
|
4
8
|
|
|
5
9
|
// src/codegen/api_types_generator.ts
|
|
6
10
|
import { Node } from "ts-morph";
|
|
@@ -72,7 +76,12 @@ var ApiTypesGenerator = class {
|
|
|
72
76
|
const schema = validateUsingCallNode.getArguments()[0];
|
|
73
77
|
if (!Node.isIdentifier(schema))
|
|
74
78
|
return;
|
|
75
|
-
const
|
|
79
|
+
const implementation = schema.getImplementations().at(0);
|
|
80
|
+
if (!implementation) {
|
|
81
|
+
this.#logger.warning(`Unable to find the schema file for ${schema.getText()}`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const importPath = implementation.getSourceFile().getFilePath();
|
|
76
85
|
const relativeImportPath = relative(this.#getDestinationDirectory(), importPath);
|
|
77
86
|
return `InferInput<typeof import('${relativeImportPath}')['${schema.getText()}']>`;
|
|
78
87
|
}
|
|
@@ -109,9 +118,7 @@ var ApiTypesGenerator = class {
|
|
|
109
118
|
throw new Error("Unable to create the api.d.ts file");
|
|
110
119
|
file?.removeText();
|
|
111
120
|
file.insertText(0, (writer) => {
|
|
112
|
-
writer.writeLine(
|
|
113
|
-
`import type { MakeOptional, Serialize, Simplify, ConvertReturnTypeToRecordStatusResponse } from '@tuyau/utils/types'`
|
|
114
|
-
).writeLine(`import type { InferInput } from '@vinejs/vine/types'`).newLine().writeLine(`export interface AdonisApi {`).write(this.#generateFinalInterface(types, " ")).writeLine(`}`);
|
|
121
|
+
writer.writeLine(`import type { MakeTuyauRequest, MakeTuyauResponse } from '@tuyau/utils/types'`).writeLine(`import type { InferInput } from '@vinejs/vine/types'`).newLine().writeLine(`export interface AdonisApi {`).write(this.#generateFinalInterface(types, " ")).writeLine(`}`);
|
|
115
122
|
});
|
|
116
123
|
await file.save();
|
|
117
124
|
}
|
|
@@ -156,7 +163,7 @@ var ApiTypesGenerator = class {
|
|
|
156
163
|
continue;
|
|
157
164
|
}
|
|
158
165
|
const schemaImport = this.#extractRequest(handlerData);
|
|
159
|
-
const methods = route.methods.map((method) => method.toLowerCase()).filter((method) => method !== "head");
|
|
166
|
+
const methods = route.methods.map((method) => "$" + method.toLowerCase()).filter((method) => method !== "head");
|
|
160
167
|
const segments = route.pattern.split("/").filter(Boolean);
|
|
161
168
|
let currentLevel = types;
|
|
162
169
|
const relativePath = relative(this.#getDestinationDirectory(), file.getFilePath());
|
|
@@ -165,13 +172,14 @@ var ApiTypesGenerator = class {
|
|
|
165
172
|
currentLevel[segment] = {};
|
|
166
173
|
}
|
|
167
174
|
currentLevel = currentLevel[segment];
|
|
168
|
-
if (i
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
+
if (i !== segments.length - 1)
|
|
176
|
+
return;
|
|
177
|
+
currentLevel.$url = {};
|
|
178
|
+
for (const method of methods) {
|
|
179
|
+
currentLevel[method] = {
|
|
180
|
+
request: schemaImport ? `MakeTuyauRequest<${schemaImport}>` : "unknown",
|
|
181
|
+
response: `MakeTuyauResponse<import('${relativePath}').default['${routeHandler.method}']>`
|
|
182
|
+
};
|
|
175
183
|
}
|
|
176
184
|
});
|
|
177
185
|
}
|
|
@@ -197,20 +205,23 @@ var CodegenTypes = class extends BaseCommand {
|
|
|
197
205
|
*/
|
|
198
206
|
async run() {
|
|
199
207
|
const project = new Project({
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
manipulationSettings: { quoteKind: QuoteKind.Single },
|
|
209
|
+
tsConfigFilePath: new URL("./tsconfig.json", this.app.appRoot).pathname
|
|
202
210
|
});
|
|
203
211
|
const apiTypesGenerator = new ApiTypesGenerator({
|
|
204
212
|
project,
|
|
213
|
+
logger: this.logger,
|
|
205
214
|
appRoot: this.app.appRoot,
|
|
206
215
|
routes: await this.#getRoutes(),
|
|
207
|
-
config: this.app.config.get("tuyau")
|
|
208
|
-
logger: this.logger
|
|
216
|
+
config: this.app.config.get("tuyau")
|
|
209
217
|
});
|
|
210
218
|
await apiTypesGenerator.generate();
|
|
211
219
|
this.logger.success("Types generated successfully");
|
|
212
220
|
}
|
|
213
221
|
};
|
|
222
|
+
__decorateClass([
|
|
223
|
+
flags.boolean({ description: "Verbose logs", default: false, alias: "v" })
|
|
224
|
+
], CodegenTypes.prototype, "verbose", 2);
|
|
214
225
|
export {
|
|
215
226
|
CodegenTypes as default
|
|
216
227
|
};
|
package/build/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
@@ -18,20 +18,6 @@
|
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">=20.6.0"
|
|
20
20
|
},
|
|
21
|
-
"scripts": {
|
|
22
|
-
"clean": "del-cli build",
|
|
23
|
-
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
24
|
-
"typecheck": "tsc --noEmit",
|
|
25
|
-
"format": "prettier --write .",
|
|
26
|
-
"quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts",
|
|
27
|
-
"test": "c8 npm run quick:test",
|
|
28
|
-
"index:commands": "adonis-kit index build/commands",
|
|
29
|
-
"prebuild": "npm run clean",
|
|
30
|
-
"build": "pnpm clean && tsup-node && pnpm copy:templates && pnpm index:commands",
|
|
31
|
-
"release": "pnpm build && pnpm release-it",
|
|
32
|
-
"version": "npm run build",
|
|
33
|
-
"prepublishOnly": "npm run build"
|
|
34
|
-
},
|
|
35
21
|
"peerDependencies": {
|
|
36
22
|
"@adonisjs/core": "^6.2.0"
|
|
37
23
|
},
|
|
@@ -39,14 +25,14 @@
|
|
|
39
25
|
"ts-morph": "^22.0.0"
|
|
40
26
|
},
|
|
41
27
|
"devDependencies": {
|
|
42
|
-
"@adonisjs/assembler": "^7.
|
|
43
|
-
"@adonisjs/core": "^6.
|
|
28
|
+
"@adonisjs/assembler": "^7.5.1",
|
|
29
|
+
"@adonisjs/core": "^6.8.0",
|
|
44
30
|
"@julr/tooling-configs": "^2.2.0",
|
|
45
31
|
"@poppinss/cliui": "^6.4.1",
|
|
46
32
|
"@poppinss/matchit": "^3.1.2",
|
|
47
|
-
"@
|
|
48
|
-
"@tuyau/
|
|
49
|
-
"@
|
|
33
|
+
"@types/node": "^20.12.7",
|
|
34
|
+
"@tuyau/client": "0.0.11",
|
|
35
|
+
"@tuyau/utils": "0.0.3"
|
|
50
36
|
},
|
|
51
37
|
"publishConfig": {
|
|
52
38
|
"access": "public",
|
|
@@ -61,18 +47,6 @@
|
|
|
61
47
|
"tests/**"
|
|
62
48
|
]
|
|
63
49
|
},
|
|
64
|
-
"release-it": {
|
|
65
|
-
"git": {
|
|
66
|
-
"commitMessage": "chore(release): @tuyau/core@${version}",
|
|
67
|
-
"tagAnnotation": "release ${version}",
|
|
68
|
-
"tagName": "@tuyau/core@${version}"
|
|
69
|
-
},
|
|
70
|
-
"github": {
|
|
71
|
-
"release": true,
|
|
72
|
-
"releaseName": "@tuyau/core@${version}",
|
|
73
|
-
"web": true
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
50
|
"tsup": {
|
|
77
51
|
"entry": [
|
|
78
52
|
"./index.ts",
|
|
@@ -85,5 +59,17 @@
|
|
|
85
59
|
"format": "esm",
|
|
86
60
|
"dts": true,
|
|
87
61
|
"target": "esnext"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"clean": "del-cli build",
|
|
65
|
+
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
66
|
+
"typecheck": "tsc --noEmit",
|
|
67
|
+
"format": "prettier --write .",
|
|
68
|
+
"quick:test": "node --import=./tsnode.esm.js --enable-source-maps bin/test.ts",
|
|
69
|
+
"test": "c8 npm run quick:test",
|
|
70
|
+
"index:commands": "adonis-kit index build/commands",
|
|
71
|
+
"prebuild": "npm run clean",
|
|
72
|
+
"build": "pnpm clean && tsup-node && pnpm copy:templates && pnpm index:commands",
|
|
73
|
+
"version": "npm run build"
|
|
88
74
|
}
|
|
89
|
-
}
|
|
75
|
+
}
|