@automateinc/fleet-types 1.0.105 → 1.0.106
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/bin/fleet-types.mjs +39 -6
- package/package.json +1 -1
package/bin/fleet-types.mjs
CHANGED
|
@@ -155,7 +155,7 @@ async function generateTypes() {
|
|
|
155
155
|
const emittedPath = routerSourcePath.replace(/\.ts$/, ".d.ts");
|
|
156
156
|
const sourceFile = ts.createSourceFile(emittedPath, emittedDeclaration, ts.ScriptTarget.Latest, true);
|
|
157
157
|
const sanitizedSourceFile = sanitizeBackendTypes(ts, sourceFile);
|
|
158
|
-
const transformedSourceFile =
|
|
158
|
+
const transformedSourceFile = transformProcedures(ts, sanitizedSourceFile);
|
|
159
159
|
const statements = transformedSourceFile.statements.filter(
|
|
160
160
|
statement =>
|
|
161
161
|
ts.isImportDeclaration(statement) ||
|
|
@@ -199,7 +199,7 @@ async function generateTypes() {
|
|
|
199
199
|
console.log(`Generated ${path.relative(callerRoot, outputPath)} from ${routerSourcePath}`);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
function
|
|
202
|
+
function transformProcedures(ts, sourceFile) {
|
|
203
203
|
const procedureTypes = new Set(["TRPCMutationProcedure", "TRPCQueryProcedure", "TRPCSubscriptionProcedure"]);
|
|
204
204
|
const transformation = ts.transform(sourceFile, [
|
|
205
205
|
context => {
|
|
@@ -211,15 +211,48 @@ function transformProcedureOutputs(ts, sourceFile) {
|
|
|
211
211
|
node.typeArguments?.length
|
|
212
212
|
) {
|
|
213
213
|
const [procedureDefinition, ...remainingTypeArguments] = node.typeArguments;
|
|
214
|
+
const procedureType = node.qualifier.text;
|
|
214
215
|
|
|
215
216
|
if (ts.isTypeLiteralNode(procedureDefinition)) {
|
|
216
217
|
const members = procedureDefinition.members.map(member => {
|
|
218
|
+
if (!ts.isPropertySignature(member) || !member.type || !ts.isIdentifier(member.name)) return member;
|
|
219
|
+
|
|
217
220
|
if (
|
|
218
|
-
|
|
219
|
-
member.
|
|
220
|
-
ts.
|
|
221
|
-
member.name.text === "output"
|
|
221
|
+
procedureType === "TRPCQueryProcedure" &&
|
|
222
|
+
member.name.text === "input" &&
|
|
223
|
+
ts.isTypeLiteralNode(member.type)
|
|
222
224
|
) {
|
|
225
|
+
const inputProperties = member.type.members.filter(ts.isPropertySignature);
|
|
226
|
+
const hasInputProperty = propertyName =>
|
|
227
|
+
inputProperties.some(property =>
|
|
228
|
+
ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)
|
|
229
|
+
? property.name.text === propertyName
|
|
230
|
+
: false,
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
if (hasInputProperty("skip") && hasInputProperty("take") && !hasInputProperty("cursor")) {
|
|
234
|
+
const cursorProperty = ts.factory.createPropertySignature(
|
|
235
|
+
undefined,
|
|
236
|
+
"cursor",
|
|
237
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
238
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword),
|
|
239
|
+
);
|
|
240
|
+
const inputType = ts.factory.updateTypeLiteralNode(member.type, [
|
|
241
|
+
cursorProperty,
|
|
242
|
+
...member.type.members,
|
|
243
|
+
]);
|
|
244
|
+
|
|
245
|
+
return ts.factory.updatePropertySignature(
|
|
246
|
+
member,
|
|
247
|
+
member.modifiers,
|
|
248
|
+
member.name,
|
|
249
|
+
member.questionToken,
|
|
250
|
+
inputType,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (member.name.text === "output") {
|
|
223
256
|
return ts.factory.updatePropertySignature(
|
|
224
257
|
member,
|
|
225
258
|
member.modifiers,
|
package/package.json
CHANGED