mobx-tanstack-query-api 0.38.1 → 0.39.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/cli.cjs +71 -55
- package/cli.cjs.map +1 -1
- package/cli.d.ts +15 -2
- package/cli.js +71 -55
- package/cli.js.map +1 -1
- package/package.json +2 -2
package/cli.cjs
CHANGED
|
@@ -429,11 +429,12 @@ function generateAuxiliarySchemas(schemaKeys, schemas, schemaKeyToVarNameFn, vis
|
|
|
429
429
|
const schema = schemas[key];
|
|
430
430
|
if (!schema) continue;
|
|
431
431
|
const varName = schemaKeyToVarNameFn(key);
|
|
432
|
+
const cyclePath = /* @__PURE__ */ new Set([key]);
|
|
432
433
|
const expr = schemaToZodExpr(
|
|
433
434
|
schema,
|
|
434
435
|
schemas,
|
|
435
436
|
schemaKeyToVarNameFn,
|
|
436
|
-
|
|
437
|
+
cyclePath
|
|
437
438
|
);
|
|
438
439
|
lines.push(`export const ${varName} = ${expr};`);
|
|
439
440
|
}
|
|
@@ -912,7 +913,26 @@ const newEndpointTmpl = ({
|
|
|
912
913
|
openApiComponentsParameters: swaggerSchema?.components?.parameters ?? void 0,
|
|
913
914
|
queryParamName: queryName
|
|
914
915
|
}) : null;
|
|
915
|
-
const
|
|
916
|
+
const appendRuleOpt = zodContractsIsObject && zodContracts.appendRule != null ? zodContracts.appendRule : null;
|
|
917
|
+
const routeInfoForAppend = contractsVarName != null ? {
|
|
918
|
+
operationId: raw.operationId ?? "",
|
|
919
|
+
path: path2,
|
|
920
|
+
method,
|
|
921
|
+
contractName: contractsVarName
|
|
922
|
+
} : null;
|
|
923
|
+
const contractsLine = (() => {
|
|
924
|
+
if (contractsVarName == null) return "";
|
|
925
|
+
if (typeof appendRuleOpt === "string")
|
|
926
|
+
return `contracts: ${appendRuleOpt} ? ${contractsVarName} : undefined,`;
|
|
927
|
+
if (typeof appendRuleOpt === "function" && routeInfoForAppend) {
|
|
928
|
+
const include = appendRuleOpt(
|
|
929
|
+
routeInfoForAppend.contractName,
|
|
930
|
+
routeInfoForAppend
|
|
931
|
+
);
|
|
932
|
+
return include ? `contracts: ${contractsVarName},` : "contracts: undefined,";
|
|
933
|
+
}
|
|
934
|
+
return `contracts: ${contractsVarName},`;
|
|
935
|
+
})();
|
|
916
936
|
const validateContractsLine = (() => {
|
|
917
937
|
if (validateOpt === void 0) return "";
|
|
918
938
|
if (typeof validateOpt === "string")
|
|
@@ -1490,12 +1510,25 @@ const generateApi = async (params) => {
|
|
|
1490
1510
|
sortTypes: true,
|
|
1491
1511
|
templates: paths.templates.toString(),
|
|
1492
1512
|
primitiveTypeConstructs: (constructs) => {
|
|
1493
|
-
|
|
1513
|
+
const result = {
|
|
1494
1514
|
...constructs,
|
|
1495
1515
|
object: () => `Record<string, any>`,
|
|
1496
|
-
float: () => `number
|
|
1497
|
-
...params.otherCodegenParams?.primitiveTypeConstructs?.(constructs)
|
|
1516
|
+
float: () => `number`
|
|
1498
1517
|
};
|
|
1518
|
+
if (params.otherCodegenParams?.primitiveTypeConstructs) {
|
|
1519
|
+
if (typeof params.otherCodegenParams?.primitiveTypeConstructs === "function") {
|
|
1520
|
+
Object.assign(
|
|
1521
|
+
result,
|
|
1522
|
+
params.otherCodegenParams.primitiveTypeConstructs(result)
|
|
1523
|
+
);
|
|
1524
|
+
} else {
|
|
1525
|
+
Object.assign(
|
|
1526
|
+
result,
|
|
1527
|
+
params.otherCodegenParams.primitiveTypeConstructs
|
|
1528
|
+
);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return result;
|
|
1499
1532
|
},
|
|
1500
1533
|
requestOptions: params.fetchSchemaRequestOptions,
|
|
1501
1534
|
...params.otherCodegenParams
|
|
@@ -1509,6 +1542,34 @@ const generateApi = async (params) => {
|
|
|
1509
1542
|
);
|
|
1510
1543
|
return;
|
|
1511
1544
|
}
|
|
1545
|
+
const prepareConfig = (config) => {
|
|
1546
|
+
config.routes.combined?.forEach((routeInfo) => {
|
|
1547
|
+
routeInfo.routes.sort(
|
|
1548
|
+
(routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage)
|
|
1549
|
+
);
|
|
1550
|
+
});
|
|
1551
|
+
return params.otherCodegenParams?.hooks?.onPrepareConfig?.(config);
|
|
1552
|
+
};
|
|
1553
|
+
const formatRouteName = (routeInfo, usageRouteName) => {
|
|
1554
|
+
let formattedRouteName = usageRouteName;
|
|
1555
|
+
if (params.addPathSegmentToRouteName === true || typeof params.addPathSegmentToRouteName === "number") {
|
|
1556
|
+
const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === "number" ? params.addPathSegmentToRouteName : 0;
|
|
1557
|
+
const pathSegments = routeInfo.route.split("/").filter(Boolean);
|
|
1558
|
+
const { _: _2 } = codegenProcess.getRenderTemplateData().utils;
|
|
1559
|
+
formattedRouteName = _2.camelCase(
|
|
1560
|
+
`${pathSegments[pathSegmentForSuffix] || ""}_${formattedRouteName}`
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
const endpointName = formattedRouteName;
|
|
1564
|
+
const resultRouteName = params?.formatEndpointName?.(endpointName, routeInfo) ?? swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(
|
|
1565
|
+
routeInfo,
|
|
1566
|
+
endpointName
|
|
1567
|
+
) ?? endpointName;
|
|
1568
|
+
return params.otherCodegenParams?.hooks?.onFormatRouteName?.(
|
|
1569
|
+
routeInfo,
|
|
1570
|
+
resultRouteName
|
|
1571
|
+
) ?? resultRouteName;
|
|
1572
|
+
};
|
|
1512
1573
|
const inputToCodegenInput = (input) => {
|
|
1513
1574
|
const inputData = {};
|
|
1514
1575
|
if (typeof input === "string") {
|
|
@@ -1525,32 +1586,11 @@ const generateApi = async (params) => {
|
|
|
1525
1586
|
...swaggerTypescriptApiCodegenBaseParams,
|
|
1526
1587
|
...inputToCodegenInput(params.mixinInput),
|
|
1527
1588
|
hooks: {
|
|
1528
|
-
onInit: (configuration) => {
|
|
1589
|
+
onInit: (configuration, codegenProcess2) => {
|
|
1529
1590
|
mixinSwaggerSchema = lodashEs.cloneDeep(configuration.swaggerSchema);
|
|
1530
1591
|
},
|
|
1531
|
-
onPrepareConfig:
|
|
1532
|
-
|
|
1533
|
-
routeInfo.routes.sort(
|
|
1534
|
-
(routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage)
|
|
1535
|
-
);
|
|
1536
|
-
});
|
|
1537
|
-
},
|
|
1538
|
-
onFormatRouteName: (routeInfo, usageRouteName) => {
|
|
1539
|
-
let formattedRouteName = usageRouteName;
|
|
1540
|
-
if (params.addPathSegmentToRouteName === true || typeof params.addPathSegmentToRouteName === "number") {
|
|
1541
|
-
const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === "number" ? params.addPathSegmentToRouteName : 0;
|
|
1542
|
-
const pathSegments = routeInfo.route.split("/").filter(Boolean);
|
|
1543
|
-
const { _: _2 } = codegenProcess.getRenderTemplateData().utils;
|
|
1544
|
-
formattedRouteName = _2.camelCase(
|
|
1545
|
-
`${pathSegments[pathSegmentForSuffix] || ""}_${formattedRouteName}`
|
|
1546
|
-
);
|
|
1547
|
-
}
|
|
1548
|
-
const endpointName = formattedRouteName;
|
|
1549
|
-
return params?.formatEndpointName?.(endpointName, routeInfo) ?? swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(
|
|
1550
|
-
routeInfo,
|
|
1551
|
-
endpointName
|
|
1552
|
-
) ?? endpointName;
|
|
1553
|
-
}
|
|
1592
|
+
onPrepareConfig: prepareConfig,
|
|
1593
|
+
onFormatRouteName: formatRouteName
|
|
1554
1594
|
}
|
|
1555
1595
|
});
|
|
1556
1596
|
}
|
|
@@ -1576,32 +1616,8 @@ const generateApi = async (params) => {
|
|
|
1576
1616
|
codeGenProcessFromInit
|
|
1577
1617
|
);
|
|
1578
1618
|
},
|
|
1579
|
-
onPrepareConfig:
|
|
1580
|
-
|
|
1581
|
-
routeInfo.routes.sort(
|
|
1582
|
-
(routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage)
|
|
1583
|
-
);
|
|
1584
|
-
});
|
|
1585
|
-
return swaggerTypescriptApiCodegenBaseParams?.hooks?.onPrepareConfig?.(
|
|
1586
|
-
config
|
|
1587
|
-
);
|
|
1588
|
-
},
|
|
1589
|
-
onFormatRouteName: (routeInfo, usageRouteName) => {
|
|
1590
|
-
let formattedRouteName = usageRouteName;
|
|
1591
|
-
if (params.addPathSegmentToRouteName === true || typeof params.addPathSegmentToRouteName === "number") {
|
|
1592
|
-
const pathSegmentForSuffix = typeof params.addPathSegmentToRouteName === "number" ? params.addPathSegmentToRouteName : 0;
|
|
1593
|
-
const pathSegments = routeInfo.route.split("/").filter(Boolean);
|
|
1594
|
-
const { _: _2 } = codegenProcess.getRenderTemplateData().utils;
|
|
1595
|
-
formattedRouteName = _2.camelCase(
|
|
1596
|
-
`${pathSegments[pathSegmentForSuffix] || ""}_${formattedRouteName}`
|
|
1597
|
-
);
|
|
1598
|
-
}
|
|
1599
|
-
const endpointName = formattedRouteName;
|
|
1600
|
-
return params?.formatEndpointName?.(endpointName, routeInfo) ?? swaggerTypescriptApiCodegenBaseParams?.hooks?.onFormatRouteName?.(
|
|
1601
|
-
routeInfo,
|
|
1602
|
-
endpointName
|
|
1603
|
-
) ?? endpointName;
|
|
1604
|
-
}
|
|
1619
|
+
onPrepareConfig: prepareConfig,
|
|
1620
|
+
onFormatRouteName: formatRouteName
|
|
1605
1621
|
}
|
|
1606
1622
|
});
|
|
1607
1623
|
const utils = codegenProcess.getRenderTemplateData().utils;
|